点删除按钮后, 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>

解决方案 »

  1.   

    先从datagrid中取得该控件的值
    string strSex = ((CheckBox)(e.Item.Cells[列数-1].FindControl("cbSex"))).Checked.ToString ();
    然后在查询出id即可
      

  2.   

    这个是我写的删除类
    参考一下。
    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>
    /// DeleteQiantai 的摘要说明
    /// </summary>
    public class DeleteQiantai
    {
        public DataGrid DataGrid1;
        public DeleteQiantai()
    {        //
            // TODO: 在此处添加构造函数逻辑
            //
    }
        public void DeleteQiansupply(DataGrid DGrid, string strsql)
        {
            DataGrid1 = DGrid;
            ArrayList alist = new ArrayList();
            System.Web.UI.WebControls.CheckBox box;
            for (int i = 0; i < DataGrid1.Items.Count; i++)
            {
                box = ((CheckBox)this.DataGrid1.Items[i].Cells[3].FindControl("CheckBox1"));
                if (box.Checked)
                {
                    alist.Add(box.Text);            }
            }        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["Str_sql"]);
            con.Open();
            int id = 0;
            for (int i = 0; i < alist.Count; i++)              //循环 更新 被选种的项
            {            id = Convert.ToInt32(alist[i]);
                SqlCommand cmd_updata = new SqlCommand(strsql + "'" + id.ToString() + "'", con);
                //   System.Web.HttpContext.Current.Response.Write(strsql+"'"+id.ToString()+"'"+"<br>");
                cmd_updata.ExecuteNonQuery();
            }
            con.Close();
            System.Web.HttpContext.Current.Response.Write("<script>alert('操作成功!');</script>");
        }
      

  3.   

    我这样写 string SelFid = "";
    for(int i=0;i<this.DataListDept.Items.Count;i++)   
    {
    CheckBox chkBox=(CheckBox)this.DataListDept.Items[i].Cells[1].FindControl("CheckBoxDel"); 
    if(chkBox.Checked==true)   

    SelFid +=chkBox.Text+ ",";
    }   

    最后得到的值是:SelFid为空呀,
    第一列是Fid,要取这一列的值(如果第二列选中),第二列是模板列,checkbox
      

  4.   

    在pageLoad里面你是不是加了绑定数据源的代码.
      如果有,请加上 ispostback.
     
    否则重新加载页面会重置所有的 CheckBox.