且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从数据表中删除行

更新时间:2023-02-02 20:44:18

尝试写作dtp.acceptChanges();



看看是否有效。



如果能解决您的问题,请将此标记为已解答。


 for(int i = dtP .Rows.Count-1; i> = 0; i--)
{
DataRow dr = dtP.Rows [i];
if(dr [name] ==Joe)
dr.Delete();
}

希望这是你要找的..


for(int i = dtP.Rows.Count-1; i> = 0; i--)

{

if(dtP.Rows [i] [Col_Name])=Value)

{

dtP.Rows [i] .delete();

}



})

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();

Try writing dtp.acceptChanges();

See if this works.

Please mark this as answered if this solves your problem.


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..


for(int i = dtP.Rows.Count-1; i >= 0; i--)
{
if(dtP.Rows[i]["Col_Name"])="Value")
{
dtP.Rows[i].delete();
}

})