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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 895
1 OriginalGriff 523
2 thatraja 245
3 Abhinav S 243
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,142
1 OriginalGriff 4,665
2 Peter Leow 3,774
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 15 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid