Keep the dropdownlist selected value
RowDataBound event
Protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
{
Int I;
For (I = 0; I <GridView1.Rows. Count; I ++)
{
If (e. Row. RowType = DataControlRowType. DataRow)
{
E. Row. Attributes. Add ("onmouseover", "c = this. style. backgroundColor; this. style. backgroundColor = '# ffffcc '");
E. Row. Attributes. Add ("onmouseout", "this. style. backgroundColor = c ");
}
}
E. Row. Attributes ["style"] = "Cursor: hand ";
// Bind the selected value to the question category drop-down list
If (DropDownList) e. Row. FindControl ("ddlProVar "))! = Null)
{
DropDownList ddlProVar = (DropDownList) e. Row. FindControl ("ddlProVar ");
SetSelectedItem (ddlProVar, (HiddenField) e. Row. FindControl ("hdProVarState"). Value );
}
}
/// <Summary>
/// Save the selected dropdownlist Value
/// </Summary>
/// <Param name = "list"> </param>
/// <Param name = "value"> </param>
Private void SetSelectedItem (System. Web. UI. WebControls. ListControl list, String value)
{
Foreach (ListItem e in list. Items)
{
If (e. Text = value)
{
E. Selected = true;
Return;
}
Else e. Selected = false;
}
}