Solved

Populating DropDownlist in repeater based on value of other DropDownList in a repeater

Posted on 2013-06-18
3
357 Views
Last Modified: 2013-08-06
Hello,

I have a reserved seating app that needs to allow the user to define section, row, seat based on a database that contains a list of available seats. The repeater looks like this...

Ticket 1   [ddlSection]  [ddlRow]  [ddlSeat]
Ticket 2   [ddlSection]  [ddlRow]  [ddlSeat]
Ticket 3   [ddlSection]  [ddlRow]  [ddlSeat]

If the user selects section from Ticket1.ddlSection, the Ticket1.ddlRow should update based on available rows in the section. How do I handle this? Do I use the ItemCommand of the repeater? How do I get the "onselectedindexchanged" to fire within the repeater? Any help would be appreciated. Please include a little example code.
0
Comment
Question by:tatton777
3 Comments
 
LVL 12

Expert Comment

by:jitendra patil
ID: 39259010
can you post your code here, so we can review and extend it for your solution.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 39261003
What you would be doing is add SelectedIndexChanged for the dropdownlists.
e.g. say these are two dropdownlists inside a repeater:
<asp:DropDownList ID="ddlCategory" runat="server" AppendDataBoundItems="false" DataSourceID="SqlDataSource5"
                     DataTextField="CategoryName" DataValueField="CategoryId" AutoPostBack="true" OnSelectedIndexChanged="ddlCategories_SelectedIndexChanged" >
                 </asp:DropDownList>

<asp:DropDownList ID="ddlProducts" runat="server" DataTextField="ProductName" DataValueField="ProductID" OnSelectedIndexChanged="ddlProducts_SelectedIndexChanged"></asp:DropDownList>

Here's the SelectedIndexchanged for two DDL:

//First DDL
protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e)
    {
        RepeaterItem row = (RepeaterItem)((sender) as Control).NamingContainer;

        // get the value from the first dropdownlist
        DropDownList ddlCategory = ((sender) as DropDownList);
        int categoryId = Convert.ToInt32(ddlCategory.SelectedValue);
       
        // Get Second dropdown and data for second dropdown passing the first selected value.

        DropDownList ddlProducts = row.FindControl("ddlProducts") as DropDownList;
        //Get data for second ddl and bind it.
        ddlProducts.DataSource =  GetSecondDDL DataBind using FirstDDL Selectedvalue;
        ddlProducts.DataBind();
    }
   //Second DDL
    protected void ddlProducts_SelectedIndexChanged(object sender, EventArgs e)
    {
         //Here you do the same as first but for third ddl.
    }

Open in new window

0
 
LVL 1

Author Comment

by:tatton777
ID: 39263841
Sweet. I'll plug this in to my code an let you now how it goes. Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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