Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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