急!gridview问题!新手求救!
不多说,直接来问题:
后台代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
string 学号 = GridView1.DataKeys[e.RowIndex].Value.ToString();
string 课程号 = (GridView1.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox).Text.ToString();(出错!指定参数超出有效范围 参数名:index)
string 成绩 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString();
string 备注 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString();
String mys = "server=HCZ-PC;database=xscjgl; User ID=sa;pwd=sa;Trusted_Connection=no";
SqlConnection mycon1 = new SqlConnection(mys);
mycon1.Open();
string sql = "update sc set 成绩='" + 成绩 + "', 备注='" + 备注 + "'where 学号='" + 学号 + "' and 课程号='" + 课程号 + "' ";
SqlCommand mycom2 = new SqlCommand(sql, mycon1);
mycom2.ExecuteNonQuery();
mycom2.Dispose();
mycon1.Close();
GridView1.EditIndex = -1;
bind();
}
catch(Exception ee)
{
Response.Write("<script>alert('"+ ee.Message+"')</scrip>");
}
}
附:在string 学号 = GridView1.DataKeys[e.RowIndex].Value.ToString();学号有值,但是到课程号的就没有值,我用try ……catch检测不到出错!
各位高手帮帮忙啊!
在网上找了半天的方法,也试了半天就是搞不出来,我是新手!
------解决方案--------------------
GridView1.Rows[行索引].Cells[列索引].Text