Click here to Skip to main content
12,691,702 members (30,892 online)
Rate this:
 
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
Updated 21-Mar-12 20:47pm
sravani.v15.9K
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 22 Mar 2012
Copyright © CodeProject, 1999-2017
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