re-binding dropdownlist

Posted on 2014-08-24
Last Modified: 2014-08-26
I'm constructing a little page that allows a teacher to assign a student in a class to a group. To select the student I use 2 dropdownlists. The first one is for the last name. The second one is for the first name. This way if there are 2 students with the same last name I can choose which one I want. To test this out I have two students in the database, BooBoo Bear and Bam Bam Rubble.

This is what happens. If I choose "Bear" for the last name after the page loads Boo Boo is the only choice for first name. This is what I expected. If I change my mind and select "Rubble" for the last name then both Boo Boo and Bam Bam are displayed. If I change my mind again and select "Bear" again the First Name dropdownlist then shows Boo Boo, Bam Bam, and then Boo Boo again. Auto Postback is set to true. Below is the applicable code. I did try to re-bind the FirstName dropdownlist but that didn't work.

    <div id="divLastName" style="position:absolute; top:120px; left:25px; width:150px; text-align: left;">
        <asp:Label ID="lblLastName" runat="server" Text="Last Name"></asp:Label>
        <asp:DropDownList ID="ddlLastName" runat="server" DataSourceID="sdsLastName" AutoPostBack="True" DataTextField="LastName" DataValueField="LastName" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlLastName_SelectedIndexChanged">
            <asp:ListItem Value="0">&lt;--Select Name--&gt;</asp:ListItem></asp:DropDownList>
    <div id="divFirstName" style="position:absolute; top:120px; left:185px; width:150px; text-align: left;">
        <asp:Label ID="lblFirstName" runat="server" Text="First Name"></asp:Label>
        <asp:DropDownList ID="ddlFirstName" runat="server" DataSourceID="sdsFirstName" DataTextField="FirstName" DataValueField="FirstName" AutoPostBack="True" AppendDataBoundItems="true">
            <asp:ListItem Value="0">&lt;--Select Name--&gt;</asp:ListItem></asp:DropDownList>

    <asp:SqlDataSource ID="sdsLastName" runat="server" ConnectionString="<%$ ConnectionStrings:SchoolDirectory %>" ProviderName="<%$ ConnectionStrings:SchoolDirectory.ProviderName %>" SelectCommand="usp_GetLastNameByClassID_byRB" SelectCommandType="StoredProcedure">
            <asp:ControlParameter ControlID="ddlClassList" Name="p_ClassID" PropertyName="SelectedValue" Type="Int32" />
    <asp:SqlDataSource ID="sdsFirstName" runat="server" ConnectionString="<%$ ConnectionStrings:SchoolDirectory %>" ProviderName="<%$ ConnectionStrings:SchoolDirectory.ProviderName %>" SelectCommand="usp_GetFirstNameByLastName_byRB" SelectCommandType="StoredProcedure">
            <asp:ControlParameter ControlID="ddlClassList" Name="p_ClassID" PropertyName="SelectedValue" Type="String" />
            <asp:ControlParameter ControlID="ddlLastName" Name="p_LastName" PropertyName="SelectedValue" Type="String" />
    </asp:SqlDataSource> C#
    protected void ddlLastName_SelectedIndexChanged(object sender, EventArgs e)
Question by:bobbellows
    LVL 43

    Accepted Solution

    What happens if you change that setting to false ?

    ps.  This sounds over complex having two separate control list for first and last names rather than just one for the complete name (and the user can still select the wrong one, so IMHO it won't reduce the chance of incorrect entry)

    Author Comment

    I see what you're saying. In fact it might even increase the chance of a mistake. The names are only stored as FirstName and LastName. I'm somewhat new to c# programming and only a little more experienced with I'm not sure how to build a dataset of FirstName+LastName. BTW the append = False worked. Thanks. Sorry for the delay. My day job kept me from getting back to this till now.

    If you can point me in a direction for the other dataset, I'll start working on that. Again. Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming. provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
    Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

    758 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

    11 Experts available now in Live!

    Get 1:1 Help Now