高手進來瞧瞧
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e){
string Num = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
SqlConnection conn = new SqlConnection("server=toolingsql64;uid=sa;pwd=123456789;database=GoodView");
conn.Open();
string sqlstr = "update userinfo set username='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + "',password='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim() + "' where userid='"+Num+"'";
SqlCommand objcom = new SqlCommand(sqlstr, conn);
objcom.ExecuteNonQuery();
conn.Close();
GridView1.EditIndex = -1;
this.bing();
}
觸發這個事件sqlstr update語句就報錯... 什麼原因? --------------------编程问答-------------------- 报什么错误? --------------------编程问答-------------------- 报的错误黏贴出来才知道是什么错误啊 --------------------编程问答-------------------- LZ的代码练练手还是可以的,在实际项目中这种写法是不被允许的,
起码要做到sql语句参数化这一点 --------------------编程问答-------------------- Specified argument was out of the range of valid values.
Parameter name: index
报这个错误 --------------------编程问答-------------------- Specified argument was out of the range of valid values.
Parameter name: index
报这个错误 --------------------编程问答-------------------- 我只是想在gridview里点击编辑列的时候,把name 和password列变成textBox让用户输入 --------------------编程问答--------------------
错误提示
指定的参数已超出有效值的范围。
参数名:索引
看看你传入的值吧 --------------------编程问答-------------------- 改了下 值是取出来了..但我想在gridview里点击编辑列的时候,把name 和password列变成textBox让用户输入
要怎么实现? --------------------编程问答-------------------- 是不是传入的值根本就没获取到。 --------------------编程问答-------------------- 模板列,直接绑定数据库字段 --------------------编程问答--------------------
<asp:TemplateField HeaderText="username">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("username") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("usename") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
补充:.NET技术 , ASP.NET