Solved

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

Posted on 2013-06-18
3
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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