保持dropdownlist选中值

RowDataBound事件  protectedvoidGridView1_RowDataB
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

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

本文来源21aspnet,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/3660

发表评论