Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-21
3
Medium Priority
?
823 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
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
ALaRiva earned 1000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

971 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