如何获取所选复选框值的值 [英] how to get value of selected checkboxes value

查看:50
本文介绍了如何获取所选复选框值的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datalist controle里面我有一个单行的复选框我有6个复选框,我想找出在itemcommand事件上检查的复选框的id我怎么能找到

以下是我的datalist

 <   asp:DataList     ID   =  dl_checkoutitem    runat   =  server   宽度  =  100%  

< span class =code-attribute> onitemcommand = dl_checkoutitem_ItemCommand < span class =code-keyword>>
< ItemTemplate >
< asp:表 ID = tbl_dal runat = server CssClass = table table-striped table-hover table-bordered >

< asp:TableRow >
< asp:TableCell 宽度 = 3% > < ; asp:标签 ID = lbl_sn
runat = server > < / asp:标签 > < / asp:TableCell >
< asp:TableCell 宽度 = 15% > <% #Eval( User_name%> < / asp:TableCell >
< asp:TableCell 宽度 = 20% > < ; asp:标签 ID = lbl_quantity runat = server 文本 =' <% #Eval( 电子邮件%> ' > s < / asp:Label > < / asp:TableCell >
< asp:TableCell 宽度 = 9% > < ; asp:标签 ID = lbl_price runat = 服务器 文本 =' <% #Eval( Contact_no%> ' < span class =code-keyword>> < / asp:Label < span class =code-keyword>> < / asp:TableCell < span class =code-keyword>>
< asp:TableCell 宽度 = 9% > < asp:CheckBox ID = CheckBox6 runat = server / > < / asp:TableCell >
< asp:TableCell 宽度 = 9% > < asp:CheckBox ID = CheckBox7 runat = server / > < / asp:TableCell >
< asp:TableCell 宽度 = 9% > < asp:CheckBox ID = CheckBox8 runat = 服务器 / > < / asp:TableCell >
< asp:TableCell 宽度 = 9% > < asp:CheckBox < span class =code-attribute> ID = CheckBox9 runat = 服务器 / > < / asp:TableCell >
< asp:TableCell 宽度 = 9% > < asp:CheckBox < span class =code-attribute> ID = CheckBox10 runat = 服务器 / > < / asp:TableCell >
< asp :TableCell 宽度 = 8 > < < span class =code-leadattribute> asp:按钮 ID = btn_save runat = server 文本 = save < span class =code-attribute> CssClass = btn CommandName = update CommandArgument =' <% #Eval( id)< span class =code-pagedirective>%> ' / > < / asp:TableCell >
< / asp:TableRow >
< / asp:表 >
< / ItemTemplate >
< / asp:DataList >

解决方案

您好b $ b

尝试此代码.. < br $> b $ b





<前lang =cs> 受保护 void dl_checkoutitem_ItemCommand( object source,DataListCommandEventArgs e)
{
string [] checkboxes = { CheckBox6 CheckBox7 < span class =code-string> CheckBox8, CheckBox9 CheckBox10};
string [] checkedCheckboxIds = checkboxes.Where(k = > (e.Item。 FindControl(k) as CheckBox).Checked).ToArray();

}


i have an datalist controle inside it i have checkboxes for a single row i have 6 checkboxes and i want to find out the id of checkboxes which is checked on itemcommand event how can i findout
below is my datalist

<asp:DataList ID="dl_checkoutitem" runat="server" Width="100%"

                                    onitemcommand="dl_checkoutitem_ItemCommand" >
                            <ItemTemplate>
                           <asp:Table ID="tbl_dal" runat="server" CssClass="table table-striped table-hover table-bordered">

                            <asp:TableRow>
                            <asp:TableCell Width="3%" > <asp:Label ID="lbl_sn" runat="server"></asp:Label> </asp:TableCell>
                             <asp:TableCell Width="15%" >  <%#Eval("User_name")%>  </asp:TableCell>
                              <asp:TableCell Width="20%" ><asp:Label ID="lbl_quantity" runat="server" Text='<%#Eval("Email")%>'>s</asp:Label>  </asp:TableCell>
                              <asp:TableCell Width="9%" ><asp:Label ID="lbl_price" runat="server" Text='<%#Eval("Contact_no")%>' ></asp:Label>   </asp:TableCell>
                              <asp:TableCell Width="9%" ><asp:CheckBox ID="CheckBox6" runat="server" /></asp:TableCell>
                              <asp:TableCell Width="9%" ><asp:CheckBox ID="CheckBox7" runat="server" /></asp:TableCell>
                              <asp:TableCell Width="9%" ><asp:CheckBox ID="CheckBox8" runat="server" /></asp:TableCell>
                              <asp:TableCell Width="9%" ><asp:CheckBox ID="CheckBox9" runat="server" /></asp:TableCell>
                              <asp:TableCell Width="9%" ><asp:CheckBox ID="CheckBox10" runat="server" /></asp:TableCell>
                              <asp:TableCell Width="8"> <asp:Button ID="btn_save" runat="server" Text="save" CssClass="btn"  CommandName="update" CommandArgument='<%#Eval("id") %>' /></asp:TableCell>
                              </asp:TableRow>
                             </asp:Table>
                            </ItemTemplate>
                          </asp:DataList>

解决方案

Hi
Try this code..



protected void dl_checkoutitem_ItemCommand(object source, DataListCommandEventArgs e)
       {
           string[] checkboxes = { "CheckBox6", "CheckBox7", "CheckBox8", "CheckBox9", "CheckBox10" };
          string[] checkedCheckboxIds = checkboxes.Where(k=> (e.Item.FindControl(k) as CheckBox).Checked).ToArray();

       }


这篇关于如何获取所选复选框值的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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