从数据列表获取复选框值 [英] Get checkbox value from Datalist

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

问题描述

这是我的代码:

Here is my code:

<asp:DataList ID="DataList1" runat="server" DataKeyField="iPKImage" DataSourceID="SqlDataSource2"

               RepeatLayout="Flow" RepeatDirection="Horizontal">
               <ItemTemplate>
                   <div class="thumb">
                       <a href='<%# "library_image.aspx?imageid=" & Eval("iPKImage") %>'>
                           <asp:Image ID="imgThumb" ImageUrl='<%# "showthumbnail.aspx?img=" & Eval("iPKImage") %>'

                               CssClass="thumbImage" runat="server" />
                       </a>
                       <asp:HyperLink ID="hlTitle" CssClass="thumbTitle" runat="server" Text='<%#Eval("Image")%>'></asp:HyperLink>
                       <div class="thumbOptions">
                           <table>
                               <tr>
                                   <td>
                                       <a href='<%# "library_image.aspx?imageid=" & Eval("iPKImage") %>'>
                                           <img src="skins/common/icons/ico_img_view.gif" alt="View image details" /></a>
                                   </td>
                                   <td>
                                       <asp:ImageButton ID="btnRequest" ImageUrl="~/skins/common/icons/ico_img_request.gif"

                                           runat="server" CommandName="AddToCart" ToolTip="Add to my image request list" />
                                   </td>
                                   <td>
                                       <asp:ImageButton ID="btnDisseminate" ImageUrl="~/skins/common/icons/ico_img_disseminate.gif"

                                           runat="server" CommandName="AddToCart" ToolTip="Add to my image dissemination list" />
                                   </td>
                                   <td>
                                       <asp:ImageButton ID="btnEdit" ImageUrl="~/skins/common/icons/ico_img_edit.gif" runat="server"

                                           CommandName="EditImage" ToolTip="Edit image" Visible="false" />
                                   </td>
                                   <td>
                                       <asp:ImageButton ID="btnDelete" ImageUrl="~/skins/common/icons/ico_del.gif" runat="server"

                                           CommandName="Delete" ToolTip="Delete image" Visible="false" />
                                   </td>
                                   <td>
                                       <asp:CheckBox  ID="cbDownload" runat="server" />
                                       <asp:HiddenField ID="hdnImageID" Value='<%# Eval("iPKImage") %>' runat="server" />
                                   </td>
                               </tr>
                           </table>
                       </div>
                   </div>
               </ItemTemplate>
           </asp:DataList>



现在,如何找到复选框是否已选中,如果要选中该复选框,请在旁边的隐藏字段"中选择该值?



Now, how can I find if a checkbox is checked, and if it is, select the value in the Hidden Field next to it? Thanks in advance!

推荐答案

解决了自己...抱歉!

Solved myself...sorry!

Dim IDList As New List(Of Int32)
        For Each dl As DataListItem In DataList1.Items
            If (CType(dl.FindControl("cbDownload"), CheckBox).Checked) Then
                IDList.Add(Int32.Parse(CType(dl.FindControl("hdnImageID"), HiddenField).Value))
            End If
        Next



请尝试以下..可能会有所帮助

Dim Dl As String =已检查的数据列表项目:< br/>"
对于每个dli作为DataList1.Items中的DataListItem
昏暗的chk为CheckBox = DirectCast(dli.FindControl("CategoryID"),CheckBox)
如果chk.Checked然后
dl + =(chk.Text +< br/>")
如果结束
下一个
DlLiteral.Text = Dl


请参考 [

plz try below..it may be helpfull

Dim Dl As String = "Datalist Items Checked:<br />"
For Each dli As DataListItem In DataList1.Items
Dim chk As CheckBox = DirectCast(dli.FindControl("CategoryID"), CheckBox)
If chk.Checked Then
Dl += (chk.Text + "<br />")
End If
Next
DlLiteral.Text = Dl


refer this[^]


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

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