문제

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 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:

 <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

2XLarge

3XLarge

4XLarge

5XLarge


    </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:

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. You might want to add something into the datalist item to identify the actual entity corresponding to the checkbox.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top