Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
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 26-Sep-11 4:26am
ManavGuru3.2K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

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.
  Permalink  
Comments
crranasinghe at 25-Jul-13 4:15am
   
This works fine thanks..........
Suresh_Kumar_Trichy at 11-Nov-14 1:08am
   
This works.. but i think not a correct way to approach.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You have to write code on RowUpdating Event for edit row in gridview
 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 
   }
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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.
 
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.
  Permalink  
v2
Comments
Dylan Morley at 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 at 12-Dec-12 7:13am
   
This is also accepted....Try this too... It really works..
sasikala gurusamy at 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">

<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">

<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>





 

 
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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

to edit a row in a gridview you must use the OnRowEditing event
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

add the rowediting event of grid view in .aspx.cs
 
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
   {
 
   }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

but data is not show in gridview.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 285
1 DamithSL 265
2 CPallini 195
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100