【问题标题】:How to delete in datagrid as well database如何在datagrid以及数据库中删除
【发布时间】:2015-07-04 20:53:00
【问题描述】:
protected void ButtonDelete_Click(object sender, EventArgs e)
{
DataSet ds;

if (Session["location1"] != null)
{
ds = (DataSet)Session["location1"];

//int cnt = ds.Tables[0].Rows.Count;

//for (int i = 0; i < cnt; i++)
//{
//}


foreach (DataGridItem item in DataGrid1.Items)
{
HtmlInputCheckBox chk = new HtmlInputCheckBox();

chk = (HtmlInputCheckBox)item.Cells[0].FindControl("DeleteThis");
if (chk.Checked == true)
{

objaccess.Option = "AA";
string Location = item.Cells[0].Text.ToString();

//objaccess.Locationcode = item.Cells[0].Text.ToString();
// string strop = item.Cells[0].Text.ToString();
objaccess.delInvsItem();
//this.DeleteGridRow(index);

}
}

在这里,我使用上面的代码使用复选框删除了 datagrid 中的记录,而不是 gridview 中的记录。在选项“AA”中,我在后端编写了删除查询。一旦我选择了datagrid中的复选框,然后我按下了删除键,上面的函数就被完美地调用了,但是执行后记录没有被删除。

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    我不确定您的代码,但最好从数据库中删除一条记录,然后重新填充数据集。

    【讨论】:

      猜你喜欢
      • 2012-02-11
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多