在visualwebdeveloper的gridview中删除选定的行 [英] deleting the selected row in gridview at visualwebdeveloper

查看:96
本文介绍了在visualwebdeveloper的gridview中删除选定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在gridview中使用该复选框.然后我选中此复选框,按Delete键,应删除所选行..advance谢谢..

i want to use checkbox in gridview.then i select this checkbox,press the delete button ,the selected row should be deleted..advance thanks..

推荐答案



如果可以的话请尝试...

Hi,

Try this if could help...

 //instantiate new ArrayList to hold our checked items
 ArrayList checkedItems = new ArrayList();
 CheckBox chk;
 string chkBoxIndex = string.Empty;
 //loop through each row in the GridView
 foreach (GridViewRow row in GridContacts.Rows)
 {
    //get the index of the current CheckBox
    chkBoxIndex = (string)GridContacts.DataKeys[row.RowIndex].Value.ToString();
    chk = (CheckBox)row.FindControl("CheckBox1");
    if (!(Session["CheckedItems"] == null))
    {
      checkedItems = (ArrayList)Session["CheckedItems"];
    }
    if (chk.Checked)
    {
      if (!(checkedItems.Contains(chkBoxIndex)))
      {
         //add to the list
         checkedItems.Add(chkBoxIndex);
      }
      else
      {
         //remove from list since it's unchecked
         checkedItems.Remove(chkBoxIndex);
      }
    }
}
if (checkedItems.Count > 0)
{
   for (int i = 0; i < checkedItems.Count; i++)
   {
       // Your code to delete the items in you database here...
       //...
   }
}
/pre>


Regards,


我认为这篇文章对您有很大帮助:
I think this post will help you much: GridView all in one[^]


这篇关于在visualwebdeveloper的gridview中删除选定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆