Problem with checkboxes in visual web developer express 2008

Posted on 2011-10-02
Last Modified: 2012-06-27

Short description: When I choose drop-down-list or checkbox-list from the toolbox in Visual web developer express 2008, they both contain a smart tag so I can choose and configure data soure. If I choose checkbox, there is no smart tag.

My question, how do I tell the checkbox where to pick its values from the database.
For mor details. See attached file.

Best regards

Question by:marcgu
    LVL 26

    Expert Comment

    by:Anurag Thakur
    use check box list if you want to use data source
    check box is just single entity thats why smart tag is not applicable there

    Author Comment

    I know (I even wrote that in my attachted document)  but with check box list there is no way to display multiple choices if I have understood it correctly.

    For instance if the user selects both Argentina and Denmark, with checkbox list, only rows matching Argentina will be displayed.

    Could you please give a hint on where to read more about the possiblity to use checkboxes to pull data data from a database with visual web developer.

    I would be more than grateful.
    LVL 26

    Accepted Solution

    so far, when ever i have worked with check box list i have always done more than one check box selection with the data getting populated from the database
    in your case, use check box list bind it to the database

    there are 2 ways of achieving the target
    option 1
    Have a button on the page and when the button is clicked loop through the check box list, get the selected values and then show the records

    option 2
    create an event on the check box changed event and the handle the selection accordingly

    Author Comment

    Thanks a lot. Please take a look at the attached code in this comment. I am not sure where to place the loop. In the default.aspx file or in the default.aspx.vb file? Could some one give a tip on a sample loop that would fit into my code where I just have to change the ID of the checkboxlist and the selectommand?

    %@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <head runat="server">
        <form id="form1" runat="server">
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                SelectCommand="SELECT * FROM [Employees] where EmployeeID=@EmployeeID">
                    <asp:ControlParameter ControlID="CheckBoxList1" Name="EmployeeID" 
                        PropertyName="SelectedValue" />
            <asp:CheckBoxList ID="CheckBoxList1" runat="server" 
                DataSourceID="SqlDataSource2" DataTextField="EmployeeID" 
                DataValueField="EmployeeID" RepeatColumns="4">
            <asp:Button ID="Button1" runat="server" Text="Button" />
            <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
                AutoGenerateColumns="False" CellPadding="4" DataKeyNames="EmployeeID" 
                DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None">
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" 
                        InsertVisible="False" ReadOnly="True" SortExpression="EmployeeID" />
                    <asp:BoundField DataField="LastName" HeaderText="LastName" 
                        SortExpression="LastName" />
                    <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                        SortExpression="FirstName" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="TitleOfCourtesy" HeaderText="TitleOfCourtesy" 
                        SortExpression="TitleOfCourtesy" />
                    <asp:BoundField DataField="BirthDate" HeaderText="BirthDate" 
                        SortExpression="BirthDate" />
                    <asp:BoundField DataField="HireDate" HeaderText="HireDate" 
                        SortExpression="HireDate" />
                    <asp:BoundField DataField="Address" HeaderText="Address" 
                        SortExpression="Address" />
                    <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                    <asp:BoundField DataField="Region" HeaderText="Region" 
                        SortExpression="Region" />
                    <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" 
                        SortExpression="PostalCode" />
                    <asp:BoundField DataField="Country" HeaderText="Country" 
                        SortExpression="Country" />
                    <asp:BoundField DataField="HomePhone" HeaderText="HomePhone" 
                        SortExpression="HomePhone" />
                    <asp:BoundField DataField="Extension" HeaderText="Extension" 
                        SortExpression="Extension" />
                    <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
                    <asp:BoundField DataField="ReportsTo" HeaderText="ReportsTo" 
                        SortExpression="ReportsTo" />
                    <asp:BoundField DataField="PhotoPath" HeaderText="PhotoPath" 
                        SortExpression="PhotoPath" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
            SelectCommand="SELECT DISTINCT [EmployeeID] FROM [Employees]">

    Open in new window

    The default.aspx.vb -file

    Partial Class _Default
        Inherits System.Web.UI.Page
        Protected Sub SqlDataSource1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles SqlDataSource1.Load
        End Sub
        Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting
        End Sub
    End Class

    Open in new window


    Author Closing Comment

    Thanks for the information and hint where to search. I found a detailed solution in question with ID: 26853668.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now