Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi Everyone, i am using a gridview in my .aspx page,i want to edit the record by selecting the id from the gridview , that display on the page load in my.aspx page,after selection of the id this wiil be transfer these value in dropdownlist.and from there i want to update, but when i click on the edit button ,then it give error."The GridView 'GridView1' fired event RowEditing which wasn't handled.
"
Posted

BELOW IS THE CORRECT ANSWER IF YOU ARE USING ROW COMMAND FOR EDITING AND GETTING THIS ERROR.
THANKS Sasikala Gurusamy

Just change the "CommandName" property of the "Edit" button from "Edit" to "EditRow"(or something else which is relevent to you but make sure it is not "Edit"). Now surprisingly the code works fine.
 
Share this answer
 
Comments
crranasinghe 25-Jul-13 4:15am    
This works fine thanks..........
Suresh_Kumar_Trichy 11-Nov-14 1:08am    
This works.. but i think not a correct way to approach.
SathishRam 12-May-15 5:43am    
Thanks a lot !!!!!!!!!!!!!
Member 10967742 17-Sep-15 15:29pm    
thanks
mohanbeit2010 12-Dec-15 2:14am    
Why it is Not Working?
You have to write code on RowUpdating Event for edit row in gridview
C#
 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
 {
GridView1.EditIndex = e.NewEditIndex;
BindGrid();
}

protected void GridView1_RowUpdating(object sender, GridViewEditEventArgs e)
   {
 // Write here code for edit Rows 
   }
 
Share this answer
 
v2
Just change the "CommandName" property of the "Edit" button from "Edit" to "EditRow"(or something else which is relevent to you but make sure it is not "Edit"). Now surprisingly the code works fine.

SQL
Some other GridViews reserved key words and their default associated events are as follow :
    "Cancel" - Raises the RowCancelingEdit event.
    "Delete"  - Raises the RowDeleting and RowDeleted events.
    "Edit" - Raises the RowEditing events.
    "Page" - Raises the PageIndexChanging and PageIndexChanged events.
    "Select" - Raises the SelectedIndexChanging and SelectedIndexChanged events.
    "Sort" - Raises the Sorting and Sorted events.
    "Update" - Raises the RowUpdating and RowUpdated events.
 
Share this answer
 
v2
Comments
Dylan Morley 11-Dec-12 6:34am    
Why answer a year old question that already has an accepted solution? Also, your answer is wrong....see the accepted solution!!
Sasikala Gurusamy 12-Dec-12 7:13am    
This is also accepted....Try this too... It really works..
Sasikala Gurusamy 12-Dec-12 7:00am    
This is my aspx code:

<asp:GridView ID="Grid" runat="server" AllowPaging="true" AutoGenerateColumns="false"
PageSize="10" OnRowCommand="Grid_RowCommand" OnRowDeleting="Grid_RowDeleting" OnRowUpdating="Grid_RowUpdating">
<columns>
<asp:BoundField DataField="Sno" HeaderText="Sno" />
<asp:BoundField DataField="id" HeaderText="ID" />
<asp:BoundField DataField="code" HeaderText="Code" />
<asp:BoundField DataField="heading" HeaderText="Heading" />
<asp:BoundField DataField="salary" HeaderText="Salary" />
<asp:BoundField DataField="industry" HeaderText="Industry" />
<asp:BoundField DataField="area" HeaderText="Area" />
<asp:BoundField DataField="skill" HeaderText="Skill" />
<asp:BoundField DataField="edu" HeaderText="Education" />
<asp:BoundField DataField="contact" HeaderText="Contact" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:ButtonField CommandName="EditRow" DataTextField="Edit" HeaderText="Edit" />
<asp:TemplateField HeaderText="Remove">
<itemtemplate>
<span önclick="return confirm('Are you sure to Delete this Property?')">
<asp:LinkButton ID="lnkB" runat="Server" CommandArgument='<%# Eval("id") %>' CommandName="Delete"
Text="Delete">
</span>

<itemstyle width="60px">






And this is my aspx.cs code:


protected void Grid_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "Delete")
{
DataTable dt = (DataTable)ViewState["tbl"];
int id = int.Parse(e.CommandArgument.ToString());
if (dbo.deleterecords("job", "id=" + id + "") == true)
{
Fillgrid();
}

}
else if (e.CommandName == "EditRow")
{
DataTable dt = (DataTable)ViewState["tbl"];
int Rowindex = int.Parse(e.CommandArgument.ToString()) + (Grid.PageIndex * Grid.PageSize);
string id = dt.Rows[Rowindex][1].ToString();
hfid.Value = id;
txtcode.Text = dt.Rows[Rowindex][2].ToString();
txthd.Text = dt.Rows[Rowindex][3].ToString();
txtsal.Text = dt.Rows[Rowindex][4].ToString();
txtin.Text = dt.Rows[Rowindex][5].ToString();
txtarea.Text = dt.Rows[Rowindex][6].ToString();
txtskill.Text = dt.Rows[Rowindex][7].ToString();
txtedu.Text = dt.Rows[Rowindex][8].ToString();
txtcon.Text = dt.Rows[Rowindex][9].ToString();
imgsub.Visible = false;
imgupdate.Visible = true;
if (dt.Rows[Rowindex][10].ToString() == "Active")
{
rbactive.Checked = true;
rbdeactive.Checked = false;
}
else
{
rbdeactive.Checked = true;
rbactive.Checked = false;
}
}
}
catch (Exception ex)
{
Exception E = ex;
}
}


Here i used a class file DBoperations.cs:

public bool deleterecords(string tablename, string wherestr)
{
try
{

oc = new SqlCommand("delete from " + tablename + " where " + wherestr, con);
if (oc.ExecuteNonQuery() == 1)
{
return true;
}
else
{
return false;
}

}
catch (Exception exep)
{
Exception E
but data is not show in gridview.
 
Share this answer
 
to edit a row in a gridview you must use the OnRowEditing event
 
Share this answer
 
add the rowediting event of grid view in .aspx.cs

C#
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
   {

   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900