Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Guys i want to know about how to bind a records to the dropdown list which is in the gridviews item template field.
if i click edit button at runtime then that paricular rows particular dropdown should get filled with the data.
How to achieve this.
any idea??
Posted

use gridview databound event for that... refer following code

C#
protected void test_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList ddl = (DropDownList)e.Row.FindControl("yourDropDownListID");
                ddl.DataSource = //assing your datasorce here to bind to your dropdown list
                ddl.DataBind();
            }
        }
 
Share this answer
 
Hi Sachin,


on the grid row bound event

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Control ctrl = e.Row.FindControl("ddlName");
if (ctrl != null)
{
DropDownList ddl = (DropDownList)ctrl;
DataTable dt  =GetData(); // get your data either in list or datatable
ddl.DataSource = dt  ;    // Specify  here either list or datatable 
ddl.DataTextField = "Name"; // specify here  display Member
ddl.DataValueField = "Id"; // specify here  value member
ddl.DataBind();
}
}
 
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