Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
In my web page I had Gridview. I am bind datas at runtime using databind() method.
Then I have delete and edit buttons on the grid. When i click the buttons the row is deleted or edited. how to do it
 
I am using following coding for load datas
Bindgrid()
 connect.cnopen();
        SqlDataAdapter da = new SqlDataAdapter("select ITEM,QTY,RATE,Amount FROM TempSales where Billno='" + TXTBILLNO.Text + "'", connect.cn());
        DataSet ds=new DataSet();
        da.Fill(ds);
        GridView1.DataSource=ds;
        GridView1.DataBind();
 
I give the following coding for delete Row but it is not working
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
   {
       Label Control = (Label)GridView1.Rows[e.RowIndex].FindControl("ITEM");
        connect.cnopen();
       SqlCommand cmd = new SqlCommand("delete from Tempsales where Item='" + Control.Text + "'", connect.cn());
       Bindgrid();
   
   }
Posted 20-Mar-12 2:37am
devausha1.4K
Comments
Mohd Imran Saifi at 20-Mar-12 8:56am
   
what error dou you get
Mohd Imran Saifi at 20-Mar-12 8:57am
   
fetch row index at selected event of gridview.
and delete data according to that row index
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
   {
       Label Control = (Label)GridView1.Rows[e.RowIndex].FindControl("ITEM");
        connect.cnopen();
       SqlCommand cmd = new SqlCommand("delete from Tempsales where Item='" + Control.Text + "'", connect.cn());
   cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
            GridView1.dataSource = null;
 
       Bindgrid();
   
   }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

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

  Print Answers RSS
0 CPallini 465
1 Sergey Alexandrovich Kryukov 310
2 George Jonsson 269
3 Gihan Liyanage 255
4 OriginalGriff 245
0 OriginalGriff 4,903
1 CPallini 3,960
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,786
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 15 Jun 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