简体   繁体   English

从数据表中删除行

[英]Delete row from datatable

I want to delete rows from my dataset. 我想从我的数据集中删除行。 Below is the code... 以下是代码......

When the checkbox is selected a value is getting stored as a hiddenfield value 选中该复选框后,值将存储为隐藏字段值

The code is not firing. 代码没有解雇。 The values are not getting added to the "rowstodelete". 这些值未添加到“rowstodelete”中。

 protected void BtnRmvFile_Click(object sender, EventArgs e)
    {
string[] IDs = hdnFldSelectedValuesAp.Value.Trim().Split('|');


            //Code for adding items
            foreach (string Item in IDs)
            {
                try
                {
                    DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];

                    ViewState["CurrentTable"] = dtCurrentTable;

                    List<DataRow> rowsToDelete = new List<DataRow>();
                    foreach (DataRow row in dtCurrentTable.Rows)
                    {
                        if ((row["FileMasterID"] == Item))
                        {
                            rowsToDelete.Add(row);
                        }
                    }
                    foreach (DataRow row in rowsToDelete)
                    {
                        row.Delete();
                    }
                    dtCurrentTable.AcceptChanges();

                }

If you say the code is not firing i suggest to start by checking with some kind of pop up that your method(BtnRmvFile_Click) is responding. 如果你说代码没有解雇我建议首先检查一下你的方法(BtnRmvFile_Click)正在响应。 Other than that I don't know if its just the way you pasted the code but make sure the brackets are organized. 除此之外,我不知道它是否只是粘贴代码的方式,但确保括号组织。

If the method responds to the click event start debugging, see which steps are executed and what values you pass/get make sure that its what you expect. 如果方法响应click事件开始调试,请查看执行的步骤以及传递/获取的值,确保它符合您的预期。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM