|
点击编辑后,我更新里面的内容
然后点击更新,可是就是更新不了
更新按钮的代码
protected void GVeditor_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
try
{
string cj = ((TextBox)e.NewValues[5]).Text;//成绩
string kccj = ((TextBox)e.NewValues[6]).Text;//考查成绩
string xk = ((TextBox)e.NewValues[1]).Text;//学生ID
string km = ((TextBox)e.NewValues[4]).Text;//科目
string cmdtext = "update 成绩 set 成绩='" + cj + "',考查成绩='" + kccj + "' where 成绩.学生='" + xk + "' and 成绩.科目 in (select ID from 科目 where 科目.科目='" + km + "')";
SqlConnection sqlconn = new SqlConnection(sqllink.sqlconn());
sqlconn.Open();
SqlCommand sqlcomm = new SqlCommand(cmdtext, sqlconn);
sqlcomm.ExecuteNonQuery();
sqlconn.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
this.GVeditor.DataSource = gvBind();
this.GVeditor.DataBind();
GVeditor.EditIndex = -1;
}
////////////////////HTML代码
<asp:GridView ID="GVeditor" runat="server" Width="100%" Height="72px" AutoGenerateColumns="False" OnRowCancelingEdit="GVeditor_RowCancelingEdit" OnRowEditing="GVeditor_RowEditing" OnRowUpdating="GVeditor_RowUpdating" OnRowUpdated="GVeditor_RowUpdated" >
<Columns>
<asp:BoundField DataField="学号" HeaderText="学号" ReadOnly="True" />
<asp:BoundField DataField="班级" HeaderText="班级" ReadOnly="True" />
<asp:BoundField DataField="姓名" HeaderText="姓名" ReadOnly="True" />
<asp:BoundField DataField="科目" HeaderText="科目" ReadOnly="True" />
<asp:TemplateField HeaderText="成绩">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("成绩") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%#Eval("成绩") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="考查成绩">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" Text='<%#Eval("考查成绩")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#Eval("考查成绩") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
</Columns>
</asp:GridView>
感谢各位了
|
|