Mohamed Somalia

Mohamed Somalia

  • NA
  • 312
  • 3.5k

Gridview Problem

Feb 27 2017 4:32 AM
Helo, i want to update Gridview Asp.net using C#  Date not Updated please Help
 
///Gridview///
 
<asp:GridView ID="GridView1" runat="server" DataKeyNames="ID"
onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating" onrowupdated="GridView1_RowUpdated">
<Columns>
<asp:CommandField ShowEditButton ="true" />
<asp:CommandField ShowDeleteButton= "true" />
</Columns>
</asp:GridView>
///GridView Updating Code///
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
String ID = GridView1.Rows[e.RowIndex].Cells[0].Text;
String ClassName = GridView1.Rows[e.RowIndex].Cells[1].Text;
obj.con.Open();
obj.qry = "update Classreg set ClassName=@ClassName where ID=@ID";
obj.cmd = new SqlCommand(obj.qry, obj.con);
obj.cmd.Parameters.AddWithValue("ClassName", TextBox2.Text);
obj.cmd.Parameters.AddWithValue("ID", TextBox1.Text);
obj.cmd.ExecuteNonQuery();
obj.con.Close();
Response.Write(@"<script language='javascript'>alert('Record Updated.')</script>");
filldata();
}
 
 
 
 
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
filldata();
}
 
 

Answers (7)