Solved

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

Posted on 2011-03-21
3
812 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 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

11 Experts available now in Live!

Get 1:1 Help Now