protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string strPath = Server.MapPath(".\Student.mdb");
string str = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + strPath;
olecon = new OleDbConnection(str);
string olestr = "update student set StuName='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',StuSex='"
+ ((RadioButton)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',StuAddress='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "' StuShool='"
+ ((DropDownList)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).SelectedItem.Text.ToString().Trim() + "',StuClass='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + "' StuNum='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim() + "',StuBirth='"
+ ((DropDownList)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).SelectedItem.Text.ToString().Trim() + "-" + ((DropDownList)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).SelectedItem.Text.ToString().Trim() + "-"+ ((DropDownList)(GridView1.Rows[e.RowIndex].Cells[7].Controls[0])).SelectedItem.Text.ToString().Trim() + "' StuHobby='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[8].Controls[0])).Text.ToString().Trim() + "',StuPhone='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[9].Controls[0])).Text.ToString().Trim() + "' where id='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
olecom = new OleDbCommand(olestr, olecon);
olecon.Open();
olecom.ExecuteNonQuery();
olecon.Close();
GridView1.EditIndex = -1;
bind();
}
总是提示无法将类型为“System.Web.UI.WebControls.TextBox”的对象强制转换为类型“System.Web.UI.WebControls.RadioButton”。
StuSex是个单选,,StuSchool是下拉菜单,StuBirth是三个下拉菜单,StuHobby是复选框,,,运行进行修改后说数据类型不对,,无法转化,,求指教!!帮忙改一下代码大神们