求助!!
gridview的编辑功能protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
OleDbConnection conn;
conn = DB.DBconntionadmin();
conn.Open();
string ID = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
//GridViewRow row = this.GridView1.Rows[e.RowIndex]; //定义更新行对象
[color=Red] string username = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text;
string userpwd = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text;
string popedom = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text;[/color]
//string sql3 = "update admin set username='" + ((TextBox)(row.Cells[0].Controls[0])).Text.ToString() + "' and userpwd='" + ((TextBox)(row.Cells[1].Controls[0])).Text.ToString() + "' and popedom='" + ((TextBox)(row.Cells[2].Controls[0])).Text.ToString() + "' where id=" + ID;
string sql3 = "update admin set username='" + username + "' and userpwd='" + userpwd + "' and popedom='" + popedom + "' where id=" + ID;
OleDbCommand com = new OleDbCommand(sql3, conn);
com.ExecuteNonQuery();
GridView1.EditIndex = -1;
conn.Close();
getbinder();
在红色字体处报错
[color=Red]无法将类型为“System.Web.UI.WebControls.DataControlLinkButton”的对象强制转换为类型“System.Web.UI.WebControls.TextBox”。[/color]
(GridView1.Rows[e.RowIndex].Cells[1].Controls[0]))
(GridView1.Rows[e.RowIndex].Cells[2].Controls[0]))
这三次找到的控件是LinkButton不是textbox……
看看你的textbox的位置到底在gridview的什么地方…… [tk05] 解决了啊
我加了几个textbox控件 可是别的问题又来了啊!!
string ID = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
//GridViewRow row = this.GridView1.Rows[e.RowIndex]; //定义更新行对象
string username = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].FindControl("TextBox4")).Text;
string userpwd = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("TextBox5")).Text;
string popedom = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("TextBox6")).Text;
说
string popedom = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("TextBox6")).Text;
指定的参数已超出有效值的范围。
参数名: index
即便是能编辑的显示的也不是所填写的内容
显示不是0就是-1
是怎么回事呢?
页:
[1]
