如何在asp.net/vb.net中一键获取Datalist中的所有值
我在获取数据列表中的所有值时遇到问题,
这里的问题是:
我有从数据库中的表动态填充的数据列表,aspx 页面是批量订单页面,因此数据列表中有很多项目,我希望用户能够在 模式下一次选择多个订单,并在 中选择一个称为结帐的按钮,问题是如何循环遍历所有复选框和文本框并获取价值。任何想法编码都会有很大帮助,因为我根本还没有编码。
这是我的 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"/>
小
中等
大
超大号
2XL大号
3XL大号
4XL大号
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过循环单击事件中的数据列表项来实现此目的:
You can achieve this by looping through the Datalist Items in your Click Event:
回发后,循环访问数据列表的项目并使用 FindControl 获取复选框状态。您可能想在数据列表项中添加一些内容来标识与复选框对应的实际实体。
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.