代码
protected void grv_RowEditing(object sender, GridViewEditEventArgs e)
{
string name = (grv.Rows[e.NewEditIndex].Cells[1].Controls[0] as TextBox).Text;
}
或字符串名称 grv.Rows [e.NewEditIndex] .Cells [1] .Value.ToString(); //不起作用。
答案 0 :(得分:0)
您需要再次对GridView进行数据绑定,才能访问 EditItemTemplate 中的控件。所以试试这个:
GridView1.EditIndex = e.NewEditIndex;
GridView1.DataSource = somedatasource; //Bind Grid Than Find Control
GridView1.DataBind();
Textbox txt= GridView1.Rows[e.NewEditIndex].FindControl("textboxid") as TextBox;
string name = txt.TEXT
答案 1 :(得分:0)
OnRow编辑,
protected void grv_RowEditing(object sender, GridViewEditEventArgs e)
{
grv.EditIndex = e.NewEditIndex;
grv.DataBind();
//Find Controls Here like below:
Textbox txt= grv.Rows[e.NewEditIndex].FindControl("YourTextBoxID") as TextBox;
DropDownList ddl_branch = (DropDownList)grv.Rows[e.NewEditIndex].FindControl("ddl_branch");
Label lb_ = (Label)grv.Rows[e.NewEditIndex].FindControl("YourLabelID");
}