原创

保持dropdownlist选中值

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://linuxstyle.blog.csdn.net/article/details/4194627

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

文章最后发布于: 2009-05-17 12:05:00
展开阅读全文
0 个人打赏
私信求帮助

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览