如何获取gridview中模板列中控件的值?

作者:互联网   出处:控件中国网   2014-11-05 19:05:14   阅读:1

如何获取gridview中模板列中控件的值?
 
       foreach (GridViewRow gvr in gvInBillList.Rows)
       {
          TextBox t = gvr.FindControl("TextBox1") as TextBox;
          if (t != null)
          {
              t.Text = "给TextBox1赋值";
          }
       }
 
这个方法真的很实用;把代码放到Page_Load中;

其实在GridView的模板中操作真挺头疼的;也许是我真的好菜好菜;


其实其他控件还好,最疼头的应该是DropDownList吧,这个方法同样受用;

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                gvBind();

                foreach (GridViewRow gvr in gvInBillList.Rows)
                {
                    DropDownList ddlInType = gvr.FindControl("ddlInType") as DropDownList;
                    if (ddlInType != null)
                    {
                        ddlInType.DataSource = new InBillManager().GetAllInType();
                        ddlInType.DataTextField = "Name";
                        ddlInType.DataValueField = "Id";
                        ddlInType.DataBind();
                    }
                }
            }
        }

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat