AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Problem in Deleting Row in GridView........... :-(
Posted by Roopa Mukherjee on  4/25/2009 3:49:49 PM Category: Asp.Net 2.0
Add to my favorites
Email to friend
Hi..i have tried 100000000000 of times to delete a record from GridView..always i got the same error "The GridView 'GridView1' fired event RowDeleting which wasn't handled."

I have set property of GridView..i.e Auto Generate Delete Button


CODE:-


protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{

SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=demomockTest;Integrated Security=True");

SqlDataAdapter da = new SqlDataAdapter("select * from RegisteredHR ", con);

con.Open();

da.DeleteCommand = new SqlCommand("deleterow from RegisteredHR where HRID=", con);
da.DeleteCommand.ExecuteNonQuery();

con.Close();

bindgrid();

}



public void bindgrid()
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=demomockTest;Integrated Security=True");

SqlCommand cmd = new SqlCommand("select * from RegisteredHR ", con);

SqlDataAdapter da = new SqlDataAdapter("", con);

da.SelectCommand = new SqlCommand("select * from RegisteredHR", con);

DataSet ds = new DataSet();

da.Fill(ds, "data");

GridView1.DataSource = ds.Tables[0].DefaultView;

GridView1.DataBind();

}





<asp:linkbutton id="LinkButton1" runat="server" onclick="LinkButton1_Click" width="27px" xmlns:asp="#unknown">See





<asp:linkbutton id="LinkButton2" runat="server" onclick="LinkButton2_Click" xmlns:asp="#unknown">Select All

<asp:label id="Label1" runat="server" backcolor="#FFE0C0" width="62px" xmlns:asp="#unknown">
<asp:gridview id="GridView1" runat="server" xmlns:asp="#unknown">
BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Horizontal" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
Width="669px" AutoGenerateDeleteButton="True">


<asp:templatefield>

<asp:checkbox id="CheckBox1" runat="server" />




<selectedrowstyle backcolor="#738A9C" font-bold="True" forecolor="#F7F7F7" />

<headerstyle backcolor="#4A3C8C" font-bold="True" forecolor="#F7F7F7" />








Help me out

Regards

Roopa

Post Your Reply Post New Question

 Viewer's Reply
check this url
Answered By Mohit Kumar on 4/28/2009 5:36:59 AM
http://msdn.microsoft.com/en-us/library/ms972940.aspx
http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
No Nonsense XML Web Development With PHP - Free 146 Page Preview!
Oracle Magazine
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)