gridview textbox

来源:百度知道 编辑:UC知道 时间:2024/05/15 21:13:01
com.Parameters.AddWithValue("@Master_Name", ((TextBox(GridView2.Rows[e.RowIndex].FindControl("TextBox1"))).Text);
com.Parameters.AddWithValue("@Master_Id", GridView2.DataKeys[e.RowIndex].Value.ToString()); 提示索引超出范围。必须为非负值并小于集合大小。
参数名: index
是那里出了问题

for(int i=0;i<GridView1.Rows.Count;i++)
{
TextBox Tbx=(TextBox)GridView1.Rows[i].FindControl(TextBox1)
Response.Write("<script>alert('"+Tbx.Value.ToString()+"');</script>");
}

试试

事件的问题。在gridview的某些事件里,所有的行并未都创建完,比如datarowbound,datarowcreated,仅仅是某一行的行为,也就是说Rows集合并未建立完成,整个表格更没有完成,这时候用e.RowIndex去找,就会报出索引错误。
对于这类事件,对当前行的引用,最好直接用事件参数中的e,它的属性里包含当前行的引用 e.Row(这句话也只针对这类事件而已)。

补充:对了就给俺加个十分呗,错了就算了吧。呵呵。

没有设置DataKeys

某个参数的值为null