Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have 2 grid views in a page like gridview2 and gridview3, when user click on gridview3 I fetch the data and filled in gridview2 depend on unique number from gridview3 after that user can delete the data and add data in gridview2 (not from database) , I written code it's deleting data from gridview2 but row was not removing (empty row showing)





thanks

What I have tried:

stored the data in dtp datatable
in GridView3_SelectedIndexChanged
{
Session["rdt"] = dtp;
GridView2.DataSource = Session["rdt"];
GridView2.DataBind();
}
---------------------------
in GridView2_RowDeleting
int index = Convert.ToInt32(e.RowIndex);
DataTable dt = (DataTable)Session["rdt"] as DataTable;
dt.Rows[index].Delete();
Session["rdt"] = dt;
GridView2.DataSource = dt;
GridView2.DataBind();
Posted
Updated 31-Jan-18 2:50am

Try writing dtp.acceptChanges();

See if this works.

Please mark this as answered if this solves your problem.
 
Share this answer
 
Comments
Parazival 31-Jan-18 23:58pm    
Tq tq tq Prabhanjan Bujji #!# it's working 👍🏻👌🏻
for(int i = dtP.Rows.Count-1; i >= 0; i--)
{
    DataRow dr = dtP.Rows[i];
    if (dr["name"] == "Joe")
        dr.Delete();
}
Hope this is what you are looking for..
 
Share this answer
 
Comments
Parazival 31-Jan-18 8:35am    
Thanks for reply



And one thing, present from my code deleting the data but in quick watch at dt showing red colour round mark showing in each column for deleted row , I can't upload image in code project na , that's why am saying like this .
Sorry
for(int i = dtP.Rows.Count-1; i >= 0; i--)
{
if(dtP.Rows[i]["Col_Name"])="Value")
{
dtP.Rows[i].delete();
}

})
 
Share this answer
 
Comments
Parazival 31-Jan-18 8:05am    
Thanks for reply

Dtp table is in GridView3_SelectedIndexChanged event and I have deleted the data from GridView2_RowDeleting event(data available in gridview2 only) , where can I write this code
Parazival 31-Jan-18 8:33am    
And one thing, present from my code deleting the data but in quick watch at dt showing red colour round mark showing in each column for deleted row , I can't upload image in code project na , that's why am saying like this .
Sorry

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900