Click here to Skip to main content
11,411,263 members (66,296 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET WebForms
I have a Webform in ASP.Net, In this I used DropDownList,TextBox I am Entering some data into this and Using Add Button, Every Added records display in gridView(Not Connected to DataBase), Suppose if their is some mistake in any column while Adding records I want to delete that particular rows only. So could any body will help me to sort out of this problem, what kind of code i have to used, can anybody provide me the code. Thanks in Advance.......

I have used Some code shown below But Sometimes it delete two rows (2nd last and last rows) and some times only one rows...



 DataTable dt = (DataTable)Session["additems"];
        if (dt.Rows.Count > 0)
        {
            dt.Rows.RemoveAt(e.RowIndex);
        }
        Session["additems"] = dt;
        bindGrid();
Posted 21-Mar-12 20:45pm
Namit KB1.3K
Edited 21-Mar-12 20:47pm
sravani.v15.8K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     dt = (DataTable)ViewState["dt"];
     dt.Rows[e.RowIndex].Delete();
     GridView1.DataSource = dt;
     GridView1.DataBind();
 }
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 189
1 Maciej Los 98
2 OriginalGriff 88
3 Sascha Lefévre 85
4 BillWoodruff 80
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 6,983
2 Maciej Los 3,430
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web04 | 2.8.150414.5 | Last Updated 22 Mar 2012
Copyright © CodeProject, 1999-2015
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