我把number自己赋值=1就可以获取到。 估计是e.RowIndex的值出错,但是我调试的时候 int number = e.RowIndex; int id = Convert.ToInt32(GridView1.DataKeys[number].Value);//编号//这一行代码是可以正常运行的。 string userno = (this.GridView1.Rows[number].Cells[1].FindControl("lblUserNo") as Label).Text;//用户名//这一行代码就出异常
名称对不
或
看看Cells有没有值?
应该是这两个查不到值照成的。
if (e.Row.RowType == DataControlRowType.DataRow)
{}
没?
监视为null
rows于cells都没有异常,后面获取控件才有异常。
你直接写到 grid 的 rowupdating 事件里,里面有一个E的参数,有行号
string userno = (this.GridView1.Rows[行号].FindControl("lblUserNo") as Label).Text;//用户名Cells[1]. 这个可以拿了
有写commandname='Update'哦。
我的number变量是获取的e.RowIndex。
有试过去掉cells[1],但都没有效果。
if (e.Row.RowType == DataControlRowType.DataRow)
{}
没?
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.CommandName == "btnUpdate")
{}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
我把这行代码拷过去说e没有Row定义,缺少using。
恩恩,是lable哦。好的,我试试!
在GridView1的RowUpdated中取值!!
protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
string userno = (this.GridView1.Rows[number].Cells[1].FindControl("TextBox1") as TextBox).Text;
}
这个错误是发生的原因:FindControl()的时候未查找到控件。
自己好好检查一下Rows[number].Cells[1]是不是写错了,加断点调试,watch一下
估计是e.RowIndex的值出错,但是我调试的时候
int number = e.RowIndex;
int id = Convert.ToInt32(GridView1.DataKeys[number].Value);//编号//这一行代码是可以正常运行的。
string userno = (this.GridView1.Rows[number].Cells[1].FindControl("lblUserNo") as Label).Text;//用户名//这一行代码就出异常