处理DataGrid里的CheckBox列(服务端处理)

                        <asp:DataGrid ID="dbStaffList" runat="server" OnPageIndexChanged="DataGrid_PageChanged"
                            BorderColor="#93BEE2" BorderStyle="None" BorderWidth="1px" BackColor="White"
                            CellPadding="3" PageSize="15" AllowPaging="True" AutoGenerateColumns="False"
                            DataKeyField="Staff_ID" Width="100%">
                            <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
                            <AlternatingItemStyle Font-Size="12px" BackColor="#E8F4FF"></AlternatingItemStyle>
                            <ItemStyle Font-Size="12px"></ItemStyle>
                            <HeaderStyle Font-Size="12px" Font-Bold="True" ForeColor="White" BackColor="#337FB2"
                                HorizontalAlign="Center"></HeaderStyle>
                            <FooterStyle Font-Size="12px" HorizontalAlign="Right" BackColor="#E8F4FF"></FooterStyle>
                            <Columns>
                                <asp:TemplateColumn HeaderText="ID">
                                    <HeaderStyle Width="20px"></HeaderStyle>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkStaff_ID" runat="server"></asp:CheckBox>
                                    </ItemTemplate>
                                </asp:TemplateColumn>
                                <asp:HyperLinkColumn Text="真实姓名" DataNavigateUrlField="staff_id" DataNavigateUrlFormatString="../position/NewStaff.aspx?StaffID={0}&amp;ReturnPage=1"
                                    DataTextField="RealName" HeaderText="真实姓名">
                                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                </asp:HyperLinkColumn>
                                <asp:BoundColumn DataField="Mobile" HeaderText="手机">
                                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                </asp:BoundColumn>
                            </Columns>
                            <PagerStyle Font-Size="X-Small" HorizontalAlign="right" BackColor="#E8F4FF" Mode="NumericPages">
                            </PagerStyle>
                        </asp:DataGrid>

//

  private string GetSelectedItemID(string controlID)
  {
   string selectedID;
   selectedID = "";
   //遍历DataGrid获得checked的ID
   foreach (DataGridItem item in dbStaffList.Items)
   {
    if(((CheckBox)item.FindControl(controlID)).Checked==true )
     selectedID += dbStaffList.DataKeys[item.ItemIndex] + ",";
   }
   if(selectedID.Length>0)
    selectedID=selectedID.Substring(0,selectedID.Length-1);
   return selectedID;
  }
        private string GetSelectedItemID1(string controlID)
        {
            string selectedID;
            selectedID = "";
            //遍历DataGrid获得checked的ID
            foreach (DataGridItem item in dbStaffList1.Items)
            {
                if (((CheckBox)item.FindControl(controlID)).Checked == true)
                    //selectedID += dbStaffList1.DataKeys[item.ItemIndex] + ",";
                selectedID += item.Cells[1].Text.ToString() + ",";
            }
            if (selectedID.Length > 0)
                selectedID = selectedID.Substring(0, selectedID.Length - 1);
            return selectedID;
        } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值