Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DataRowView drv = e.Row.DataItem as DataRowView;
DropDownList ddlnric = (DropDownList)e.Row.FindControl("ddlnric");
string query = "select DISTINCT ecode from Employeesms";
SqlCommand cmd = new SqlCommand(query);
ddlnric.DataSource = GetData(cmd);
ddlnric.DataTextField = "ecode";
ddlnric.DataValueField = "ecode";
ddlnric.DataBind();
ddlnric.SelectedValue = drv["lblcode"].ToString();
}
}
}
Posted
Comments
[no name] 20-May-14 13:03pm    
Just dumping an unformatted code snippet here is not a question or a description of any kind of a problem.
saisrid 20-May-14 13:07pm    
sorry,my question is, I want to populate my dropdownlist when my gv is in editmode,i want the corresponding ID of the record to be displayed in my dropdownlist .Iam specifying the dropdownlist outside the gridview .thanks.
So, what's the issue here?
Sunasara Imdadhusen 21-May-14 2:01am    
Is there any error using this code?
Ajesh1986 25-May-14 23:55pm    
HI brother...if you have an error in using this code say what that error is ....are u using bound field or template field...and please upload the .aspx page for more clarification,

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