472,118 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,118 software developers and data experts.

CheckBoxList check all

2
I'm not sure if this should be posted in the VB forum, the .NET forum or here. I know how to create a CheckBoxList, add items and have them checked or unchecked but my problem is I'm pulling the items from a database and don't know how to have them automatically checked. Can someone help with this? Thanks.

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3. </script>
  4. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  5.     <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Name" AutoPostBack="True"></asp:CheckBoxList>
  6.     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Name] FROM [tblName]"></asp:SqlDataSource>
  7. </asp:Content>
  8.  
Aug 9 '07 #1
1 4838
prk72
2
Here is the answer:

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
  2. <script runat="server">
  3.     Protected Sub CheckBoxList1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
  4.         For Each item As ListItem In CheckBoxList1.Items
  5.             item.Selected = True
  6.         Next item
  7.     End Sub
  8. </script>
  9. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  10.     <asp:CheckBoxList ID="CheckBoxList1" runat="server"  AutoPostBack="true" DataSourceID="SqlDataSource1" 
  11.                                                                              DataTextField="Name" 
  12.                                                                              DataValueField="Name" 
  13.                                                                              OnDataBound="CheckBoxList1_DataBound" />
  14.     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT DISTINCT [Name] FROM [tblName]"></asp:SqlDataSource>
  15. </asp:Content>
  16.  
Aug 9 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Eirik Eldorsen | last post: by
2 posts views Thread by Simon Cheng | last post: by
3 posts views Thread by Dune | last post: by
6 posts views Thread by dbuchanan | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.