[Last Call] Learn how to a build a cloud-first strategyRegister Now


re-binding dropdownlist

Posted on 2014-08-24
Medium Priority
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.net C#
    protected void ddlLastName_SelectedIndexChanged(object sender, EventArgs e)
Question by:bobbellows
LVL 45

Accepted Solution

AndyAinscow earned 2000 total points
ID: 40282968
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

ID: 40287036
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 asp.net. 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.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Suggested Courses

829 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