Click here to Skip to main content
16,004,782 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
C#
 DataTable dtCurrentTable = new DataTable
for (int i = 0; i < dtCurrentTable.Rows.Count; i++)
 {
    DropDownList ddltype =
    (DropDownList)gvFormula.Rows[rowIndex].Cells[1].FindControl("ddltype");


     ddlproduct.SelectedItem.Text = dtCurrentTable.Rows[i]["ddltype"].ToString();
     rowIndex++;
 }


When I assign dropdown list value . Its showing only one value.
My requirement is to bind all the values in dropdown list when selected
Posted
Updated 3-Oct-13 17:11pm
v3
Comments
thatraja 3-Oct-13 9:31am    
Your code is confusing little bit, you have 2 dropdownlists, right? where's is it? are you trying to implement nested dropdownlist like country-state?
Bhagavan Raju M 3-Oct-13 23:19pm    
@thatraja (It is in gridview )I have date field ,every day the values must entered in that I have a dropdown list . when the user click save button the values are inserting into DB.But problem is after inserting i have display the values wrt to their controls. But dropdownlist is not binding
Still not clear. Can you elaborate again?

C#
DataSet ds = new DataSet();
     SqlDataAdapter da = new SqlDataAdapter("Select distinct(name)from employee", connection);
     da.Fill(ds);
     drpemployee.DataSource = ds;
     drpemployee.DataValueField = "name";
     drpemployee.DataBind();
     drpemployee.Items.Insert(0, "--Select--");
 
Share this answer
 
v3
try it hope it will work:
C#
DropDownList ddltype =
    (DropDownList)gvFormula.Rows[rowIndex].Cells[1].FindControl("ddltype");
       DataTable dtCurrentTable = new DataTable
for (int i = 0; i < dtCurrentTable.Rows.Count; i++)
 {
ddlproduct.Items.Insert(i,new ListItem( dtCurrentTable.Rows[i]["product"].ToString(), dtCurrentTable.Rows[i]["product"].ToString()));

}
 
Share this answer
 
v3
You need to find out Cascading dropdown in ajax or u can check it on google

www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx"


www.webcodeexpert.com/2013/07/ajax-cascadingdropdown-example-in.html

this might be useful to you
 
Share this answer
 
by two way
Suppose Datatable is dt and your datat into it.
assume Dropdownlist dr;
//ASP.NET Code
dr.DataSource=dt;
dr.DataTextField="colname";

or
for (int i=0;i<dt.rows.count;i++)>
{
dr.Items.Add(dt.Rows[i]["colname"].ToString());
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900