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

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值