简体   繁体   English

我如何使用asp.net/vb.net中的一个按钮来获取数据列表中的所有值

[英]How do I get all value in Datalist with one button in asp.net/vb.net

I'm having problem getting all the values in datalist 我在获取数据列表中的所有值时遇到问题

here is the problem: 这是问题所在:

I have datalist which is populated dynamically from table in database, the aspx page is the bulk order page so there are many items in datalist and I want the user to be able to selct multiple orders at once in 我有从数据库表中动态填充的数据列表,aspx页面是批量订单页面,因此数据列表中有很多项目,我希望用户能够一次选择多个订单 mode and select a buuton in 模式,然后在 which is called check out, The question is how do I loop throuhg all the checkboxes and textboxes and get the value. 这就是所谓的签出,问题是如何循环遍历所有复选框和文本框并获取值。 any idea a coding would help termendously as I did not code yet at all. 任何编码的想法都会对我有帮助,因为我还没有编码。

here is my aspx page: 这是我的aspx页面:

 <asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#CCCCCC" 
        BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyField="Id" 
        DataSourceID="SqlDataSource1" GridLines="Both">
    <FooterStyle BackColor="White" ForeColor="#000066" />
    <ItemStyle ForeColor="#000066" />
    <SelectedItemStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
    <FooterTemplate>
        <asp:Button ID="btnNext" runat="server" Text="CheckOut" 
            onclick="btnNext_Click" />
    </FooterTemplate>
    <ItemTemplate>
        <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
        <br />
        <asp:Image ID="Image1" ImageUrl='<%# Eval("PictureUrlMedium") %>' runat="server" />

        <br />
         <asp:Label ID="DescriptionLabel" runat="server" 
            Text='<%# Eval("Description") %>' />
        <br />
        <br />
        <asp:Table ID="Table1" runat="server">
        <asp:TableRow>
        <asp:TableCell><asp:CheckBox ID="chkSmall" runat="server" Enabled="true" Width="20px"/>

Small

Medium 介质

Large

XLarge XLarge

2XLarge 2XLarge

3XLarge 3XLarge

4XLarge 4XLarge

5XLarge 5XL大


    </ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>"  

    SelectCommand="SELECT [Id], [Title], [Description], [Price], [CategoryId], [PictureUrlSmall], [PictureUrlMedium], [PictureUrlLarge], [Deleted] FROM [Product]"></asp:SqlDataSource>

You can achieve this by looping through the Datalist Items in your Click Event: 您可以通过在Click事件中遍历数据列表项来实现此目的:

foreach(DataListItem item in YourDataList.Items){
    CheckBox chkSmall = (CheckBox)item.FindControl("chkSmall");
    chkSmall.Checked gives you the value
}

Upon postback, loop through the items of the datalist and get the checkbox status using FindControl. 回发后,循环浏览数据列表中的项目,并使用FindControl获取复选框状态。 You might want to add something into the datalist item to identify the actual entity corresponding to the checkbox. 您可能需要向数据列表项中添加一些内容,以标识与该复选框相对应的实际实体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM