本文介绍了如何在gridview中删除未绑定的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Button lb =(Button)sender;

GridViewRow gvRow =(GridViewRow)lb.NamingContainer;

int rowID = gvRow.RowIndex + 1;

if(ViewState [Data]!= null)

{

DataTable dt3 =(DataTable)ViewState [Data];

if(dt3.Rows.Count> 1)

{

if(gvRow.RowIndex< dt3.Rows.Count - 1)

{

//删除所选行数据

dt3.Rows.Remove(dt3.Rows [rowID]);

}

}

//将当前数据存储在ViewState中以供将来参考

ViewState [Data] = dt3;

//重新绑定GridView以获取更新的数据

GridView1.DataSource = dt3;

GridView1.DataBind();

}

解决方案


Button lb = (Button)sender;
GridViewRow gvRow = (GridViewRow)lb.NamingContainer;
int rowID = gvRow.RowIndex + 1;
if (ViewState["Data"] != null)
{
DataTable dt3 = (DataTable)ViewState["Data"];
if (dt3.Rows.Count > 1)
{
if (gvRow.RowIndex < dt3.Rows.Count - 1)
{
//Remove the Selected Row data
dt3.Rows.Remove(dt3.Rows[rowID]);
}
}
//Store the current data in ViewState for future reference
ViewState["Data"] = dt3;
//Re bind the GridView for the updated data
GridView1.DataSource = dt3;
GridView1.DataBind();
}

解决方案


这篇关于如何在gridview中删除未绑定的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 14:45