I am trying to do this as asked earlier. The only difference that I found is additional List item that was included in above code.
I tried to use AppendDataBou
Why are you guys suggesting to use loops, when there is a GridView
method specifically made for when a row's condition changes - the RowDataBound()
?
protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow gvRow = (GridViewRow)e.Row;
HiddenField hfAgentID = (HiddenField)gvRow.FindControl("hfAgentID");
if (hfAgentID != null)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlAgent = (DropDownList)gvRow.FindControl("ddlAgent");
ddlAgent.SelectedValue = hfAgentID.Value;
}
}
}