保持dropdownlist选中值

RowDataBound事件

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";

//问题分类下拉框绑定选中值
if (((DropDownList)e.Row.FindControl("ddlProVar")) != null)
{
DropDownList ddlProVar = (DropDownList)e.Row.FindControl("ddlProVar");

SetSelectedItem(ddlProVar, ((HiddenField)e.Row.FindControl("hdProVarState")).Value);
}

}

/// <summary>
/// 保存选定的dropdownlist值
/// </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;
}
}

你可能感兴趣的:(C++,c,UI,Web,C#)