如何获取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();
}
}
}
}