Question Listbox DataSource makes Listbox disappear

daarsk

New member
Joined
Jun 7, 2014
Messages
3
Programming Experience
5-10
First, sorry if this is not in right forum location.

Second, I don't normally ask for help, but... when your stuck, your stuck :(

Start with code, questions below...
Using Visual Studio Express 2013 for Web

HTML:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <asp:UpdatePanel runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <div id="DIV_setA" runat="server">
                <asp:Button ID="BTN_ListBox" runat="server" Text="Listbox" />
                <asp:Button ID="BTN_SomethingElse" runat="server" Text="Something Else" />

                <section id="SCT_Listbox" runat="server">
                    <asp:Button ID="BTN_ShowListbox" runat="server" Text="Show Listbox" />
                    <fieldset id="FST_Listbox" runat="server" >
                        <ol><li>
                            <asp:Label ID="LBL_ListboxLabel" runat="server" Text="Make a selection" AssociatedControlID="LBX_Listbox"/>
                            <asp:ListBox ID="LBX_Listbox" runat="server" Height="130px" Width="330px" DataSourceID="SDS_ListboxDataSource" DataTextField="Name" DataValueField="Id" />
                            <asp:SqlDataSource ID="SDS_ListboxDataSource" runat="server" ConnectionString = "<%$ ConnectionStrings:webdbConnectionString %>" />
                        </li></ol>
                        <asp:Button ID="BTN_Display" runat="server" Text="Display" />
                        <asp:Label ID="LBL_DisplayResult" runat="server" />
                    </fieldset>
                </section>
                      
                <section id="SCT_SomethingElse" runat="server">
                    Something else
                </section>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
VB.NET:
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        SCT_Listbox.Visible = False
        SCT_SomethingElse.Visible = False

    End Sub
    Protected Sub BTN_SomethingElse_Click(sender As Object, e As EventArgs) Handles BTN_SomethingElse.Click

        SCT_Listbox.Visible = False
        SCT_SomethingElse.Visible = True

        DIV_setA.Visible = True

    End Sub
    Protected Sub BTN_Listbox_Click(sender As Object, e As EventArgs) Handles BTN_ListBox.Click

        SCT_Listbox.Visible = True
        SCT_SomethingElse.Visible = False

        FST_Listbox.Visible = False

        DIV_setA.Visible = True

    End Sub
    Protected Sub BTN_ShowListbox_Click(sender As Object, e As EventArgs) Handles BTN_ShowListbox.Click

        Dim CharactersTA As New webdsTableAdapters.CharactersTableAdapter

        'this does not work...
        SDS_ListboxDataSource.SelectParameters.Add("Status", "available")
        SDS_ListboxDataSource.SelectCommand = "SELECT [Id], [Name] FROM [Characters] WHERE ([Status] = @Status) ORDER BY [Name]"

        'this does work...
        'SDS_ListboxDataSource.SelectCommand = "SELECT [Id], [Name] FROM [Characters] ORDER BY [Name]"

        LBL_DisplayResult.Text = ""

        SCT_Listbox.Visible = True
        SCT_SomethingElse.Visible = False

        FST_Listbox.Visible = True

        DIV_setA.Visible = True

    End Sub
    Protected Sub BTN_Display_Click(sender As Object, e As EventArgs) Handles BTN_Display.Click

        LBL_DisplayResult.Text = "You have selected " & LBX_Listbox.Text

        SCT_Listbox.Visible = True
        SCT_SomethingElse.Visible = False

        FST_Listbox.Visible = True

        DIV_setA.Visible = True

    End Sub

You may ask why fieldset inside section, inside div, inside updatepanel, inside content? These is stripped out scripts just to find solution to problem.

2 questions...

1) how can i get LBLDisplayResult.Text to show result from Button click event by just clicking on selection in listbox instead of "select then click button"?

2) if i use the selectparameters.add function for page... click "Listbox", click "Show Listbox", listbox shows. Click "Something Else", click "Listbox", click "Show Listbox", listbox does not show. replace selectparameters.add block with just selectcommand (without the WHERE query) and it works fine (click around and the listbox always shows when its meant too). Clearly I need the WHERE query otherwise the listbox will populate with unnecessary data.

I may not have been very clear, any questions, I may be able to shed more light on the situation.

Kind Regards,
James
 
Top Bottom