日期:2014-05-19  浏览次数:20544 次

CheckBox 删除问题,请看一下错在哪里?
点删除按钮后,

  string   SelFid   =   " ";
for(int   i=0;i <this.datagrid.Items.Count;i++)      
{
CheckBox   chkBox=(CheckBox)this.datagrid.Items[i].FindControl( "BoxDel ");  
if(chkBox.Checked==true)      
{

//SelFid   +=this.datagrid.DataKeys[i].Value+   ", ";
//datagrid     的第一列是隐藏列为id,第二列为checkbox,当checkbox选中时,取得id的值,以备以后删除
请问,应当如何写?
}      
}  


////////////////////////////////
<asp:datagrid   id= "DataListDept "   runat= "server "   Width= "100% "   AutoGenerateColumns= "False "   AllowPaging= "True "
BorderWidth= "1px "   CellPadding= "0 "   PageSize= "15 "   BorderColor= "#93BEE2 ">
<SelectedItemStyle   BackColor= "#E8F4FF "> </SelectedItemStyle>
<AlternatingItemStyle   BackColor= "#E8F4FF "> </AlternatingItemStyle>
<HeaderStyle   HorizontalAlign= "Center "   ForeColor= "White "   BackColor= "#337FB2 "> </HeaderStyle>
<Columns>
<asp:BoundColumn   Visible= "False "   DataField= "Fid "   HeaderText= "Fid "> </asp:BoundColumn>
<asp:TemplateColumn   HeaderText= "选中 ">
<HeaderStyle   Width= "60px "> </HeaderStyle>
<ItemTemplate>
<asp:CheckBox   id= "CheckBoxDel "   runat= "server "> </asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn   DataField= "FName "   HeaderText= "部门名称 "> </asp:BoundColumn>
<asp:TemplateColumn   HeaderText= "操作 ">
<HeaderStyle   HorizontalAlign= "Center "   Width= "60px "> </HeaderStyle>
<ItemStyle   HorizontalAlign= "Center "> </ItemStyle>
<ItemTemplate>
<asp:Label   id= "labEditUser "   runat= "server "> 修改 </asp:Label> &nbsp;
<asp:LinkButton   id= "LinkButDel "   runat= "server "   Text= "删除 "   CommandName= "Delete "   CausesValidation= "false "> 删除 </asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle   HorizontalAlign= "Right "   BackColor= "#E8F4FF "   Mode= "NumericPages "> </PagerStyle>
</asp:datagrid>




------解决方案--------------------
这个是我写的删除类
参考一下。
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;

/// <summary> <