Solved

How to get selected values from dropdown control with no ID?

Posted on 2011-03-21
3
818 Views
Last Modified: 2012-05-11
I have a grid that has a nested combo box control from Obout - example, http://www.obout.com/combobox/aspnet_master_detail.aspx

I have this control repeated in each row of my grid.  In order to get it to work within a grid I was told to removed the ID of the parent combo box.  This works for the front end, but now I don't know how to retrieve the values in my code behind.  How do I refer to a control with no ID explicitly set?  

My code below is returning null when I try to access the child combo box:
DropDownList ddSubGenre = (DropDownList)gvTracks.Rows[ii].Cells[5].FindControl("ddSubGenre");
// ASPX CODE
            <asp:TemplateField HeaderText="Reality Genre" ItemStyle-Width="250">
                <ItemTemplate>
                <obout:ComboBox runat="server" AutoClose="false" Width="200" Height="150"
                    DataSourceID="dsGenres" DataValueField="genre" DataTextField="genre" AppendDataBoundItems="false"
                    EmptyText="Select a Genre...">
                    <Details>                    
                        <obout:ComboBox runat="server" ID="ddSubGenre"
                            EnableLoadOnDemand="true" OnLoadingItems="Detail_LoadingItems" Width="200" Height="150"
                            DataSourceID="dsSubGenres" DataValueField="subgenre" DataTextField="subgenre"
                            EmptyText="Select a Reality Genre...">
                            <HeaderTemplate>
                                Reality Sub-Genre
                            </HeaderTemplate>
                        </obout:ComboBox>
                    </Details>
                    <HeaderTemplate>
                        Reality Genre
                    </HeaderTemplate>
                </obout:ComboBox>
                
                </ItemTemplate>
            </asp:TemplateField>



// CODE BEHIND
        for (int i = 0; i < gvTracks.Rows.Count; i++)
        {
// The parent dropdown is no longer ID="ddGenre", so I don't know how to address it
            //DropDownList ddGenre = (DropDownList)gvTracks.Rows[i].Cells[5].FindControl("ddGenre");
// This is the child dropdown and this code returns null
            DropDownList ddSubGenre = (DropDownList)gvTracks.Rows[i].Cells[5].FindControl("ddSubGenre");
}

Open in new window

0
Comment
Question by:JT_SIRO
[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
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
ALaRiva earned 250 total points
ID: 35184450
Hmmmm, the only way I can think of that might work is that in your row action event, you can iterate the controls of that row/cell for this particular type of control (or if it is the only one in that cell, even better) and then you can assign it to a variable and go from there.

There is no way of directly referring to it, so you'll have to do some logic estimation to try and grab the control.

hth

- Anthony
0
 

Author Comment

by:JT_SIRO
ID: 35185755
Good idea.  I tried this in my code-behind:
            ComboBox ddGenre = (ComboBox)gvTracks.Rows[ii].Cells[6].Controls[1];
            ComboBox ddSubGenre = (ComboBox)gvTracks.Rows[ii].Cells[6].Controls[2];  // NOt finding subgenre


The first line got the ddGenre combo box object.  But I wasn't able to get the nested / child combo box with the 2nd line.  This 3rd party control doesn't have much documentation and is a weird set up with nested combo boxes.  Any idea on how I would refer to it?  Here's my aspx code again to see how it's set up.
0
 

Author Comment

by:JT_SIRO
ID: 35185758
           <asp:TemplateField HeaderText="Reality Genre" ItemStyle-Width="250">
                <ItemTemplate>
                <obout:ComboBox runat="server" AutoClose="false" Width="200" Height="150"
                    DataSourceID="dsGenres" DataValueField="genre" DataTextField="genre" AppendDataBoundItems="false"
                    EmptyText="Select a Genre...">
                    <Details>                    
                        <obout:ComboBox runat="server" ID="ddSubGenre"
                            EnableLoadOnDemand="true" OnLoadingItems="Detail_LoadingItems" Width="200" Height="150"
                            DataSourceID="dsSubGenres" DataValueField="subgenre" DataTextField="subgenre"
                            EmptyText="Select a Reality Genre...">
                            <HeaderTemplate>
                                Reality Sub-Genre
                            </HeaderTemplate>
                        </obout:ComboBox>
                    </Details>
                    <HeaderTemplate>
                        Reality Genre
                    </HeaderTemplate>
                </obout:ComboBox>
               
                </ItemTemplate>
            </asp:TemplateField>
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

759 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