Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project

830 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