|
After clicking edit, I update the contents
Then click Update, but it wo n’t update
Update button code
protected void GVeditor_RowUpdated (object sender, GridViewUpdatedEventArgs e)
{
try
{
string cj = ((TextBox) e.NewValues [5]). Text; // score
string kccj = ((TextBox) e.NewValues [6]). Text; // Check results
string xk = ((TextBox) e.NewValues [1]). Text; // Student ID
string km = ((TextBox) e.NewValues [4]). Text; // subject
string cmdtext = "update grade set grade = '" + cj + "', test grade = '" + kccj + "' where grade. student = '" + xk + "' and grade. subject in (select ID from subject where Subject.subject = '"+ 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 code
<asp: GridView ID = "GVeditor" runat = "server" Width = "100%" Height = "72px" AutoGenerateColumns = "False" OnRowCancelingEdit = "GVeditor_RowCancelingEdit" OnRowEditing = "GVeditor_RowEditing" OnRowUpdating = "GVeditor_RowUpdating" OnRowUpdated = G >
<Columns>
<asp: BoundField DataField = "Student Number" HeaderText = "Student Number" ReadOnly = "True" />
<asp: BoundField DataField = "Class" HeaderText = "Class" ReadOnly = "True" />
<asp: BoundField DataField = "Name" HeaderText = "Name" ReadOnly = "True" />
<asp: BoundField DataField = "Subject" HeaderText = "Subject" ReadOnly = "True" />
<asp: TemplateField HeaderText = "grades">
<EditItemTemplate>
<asp: TextBox ID = "TextBox1" runat = "server" Text = '<% # Eval ("grade")%>'> </ asp: TextBox>
</ EditItemTemplate>
<ItemTemplate>
<asp: Label ID = "Label3" runat = "server" Text = '<% # Eval ("achievement")%>'> </ asp: Label>
</ ItemTemplate>
</ asp: TemplateField>
<asp: TemplateField HeaderText = "Test results">
<EditItemTemplate>
<asp: TextBox ID = "TextBox2" Text = '<% # Eval ("Exam results")%>' runat = "server"> </ asp: TextBox>
</ EditItemTemplate>
<ItemTemplate>
<asp: Label ID = "Label4" runat = "server" Text = '<% # Eval ("Exam results")%>'> </ asp: Label>
</ ItemTemplate>
</ asp: TemplateField>
<asp: CommandField ShowEditButton = "True"> </ asp: CommandField>
</ Columns>
</ asp: GridView>
Thanks guys |
|