Solved

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

Posted on 2013-06-18
3
331 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sweet. I'll plug this in to my code an let you now how it goes. Thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

15 Experts available now in Live!

Get 1:1 Help Now