How do i use the GridView1_RowUpdating event?? Can someone please post
the C# code for this...Thanks in advance
sure, i am just working on it, this is my code below:
//
//
//
protected void GridView1_RowUpdating1(object sender,
GridViewUpdateEventArgs e)
{
db2 mydb2 = new db2(); // I build a class to access and handle
the database
try
{
string courseid =
GridView1.Rows[e.RowIndex].Cells[3].Text; //get the PK
int cid = int.Parse(courseid);
string clubid =
((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text; //get
the data at your selected row
if (clubid.Length == 0)
{
Label1.Text = "ClubID should not be null";
Label1.Visible = true;
return;
}
int cbd = int.Parse(clubid);
string coursename =
((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
string introduction =
((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
string picturefile =
((TextBox)GridView1.Rows[e.RowIndex].Cells[7].Controls[0]).Text;
if (coursename.Length == 0)
{
Label2.Text = "CourseName should not be null";
Label2.Visible = true;
return;
}
else if (coursename.Length > 30)
{
Label2.Text = "CourseName should less than 30 char";
Label2.Visible = true;
return;
}
else if (introduction.Length > 200)
{
Label3.Text = "Introduction should less than 10 char";
Label3.Visible = true;
return;
}
else if (picturefile.Length > 50)
{
Label4.Text = "Picture should less than 50 char";
Label4.Visible = true;
return;
}
string holecount =
((TextBox)GridView1.Rows[e.RowIndex].Cells[8].Controls[0]).Text;
if (holecount.Length == 0)
{
Label5.Text = "HoleCount should not be null";
Label5.Visible = true;
return;
}
int hct = int.Parse(holecount);
mydb2.UpdateItem(cid,
cbd,coursename,introduction,picturefile,hct);
}
catch (Exception ex)
{
Label6.Text = ex.Message;
Label6.Visible = true;
return;
}
GridView1.EditIndex = -1;
ShowGridview1Data();
}
by the way, it is hard to read these codes , i haven't make the
comments yet, I hope it can help you