If the database is not deleted, only one row of the gridview is deleted!
In fact, you only need to delete a row in the retrieved able or dataset and then bind the data source.
However, do not execute dataset acceptchanges () because it can synchronize data changes in databases and dataset.
<Asp: gridview id = "view1" runat = "server" onrowcommand = "gridview1_rowcommand">
<Columns>
<Asp: templatefield headertext = "excluding">
<Itemtemplate>
<Asp: button id = "btndelete" runat = "server" cssclass = "button1" text = "Remove" commandname = "Del"
Commandargument = '<% # eval ("ID") %> 'onclientclick = "return window. Confirm (' Are you sure you want to divide? '); "/>
</Itemtemplate>
</ASP: templatefield>
</Columns>
</ASP: gridview>
Protected void page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
Datatable dt = new datatable ();
DT. Columns. Add (New datacolumn ("ID "));
DT. Columns. Add (New datacolumn ("name "));
Datarow DR = DT. newrow ();
Dr ["ID"] = 1;
Dr ["name"] = "XX ";
DT. Rows. Add (DR );
Dr = DT. newrow ();
Dr ["ID"] = 2;
Dr ["name"] = "YY ";
DT. Rows. Add (DR );
Viewstate ["DT"] = DT;
Databind ();
}
}
Private void databind ()
{
View1.datasource = viewstate ["DT"];
View1.databind ();
}
Protected void gridview1_rowcommand (Object sender, gridviewcommandeventargs E)
{
If (E. commandname = "Del ")
{
Int id = convert. toint32 (E. commandargument );
GridViewRow gvrow = (GridViewRow) (Button) e. CommandSource). NamingContainer );
Int index = gvrow. RowIndex;
DataTable dt = (DataTable) ViewState ["DT"];
Dt. Rows. RemoveAt (index );
DataBind ();
}