Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 11th, 2006, 09:35 AM
Registered User
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default selected value of nested repeater-build <select>

i have a drop down list (a <select> element) constructed with a repeater nested within a repeater so that i can use <optgroup>s.

<asp:Repeater ID="rptIssuesNotInRelease" runat="server" DataSourceID="sdsSectionsNotInRelease">
        <select id="ddlIssuesNotInRelease">
        <asp:HiddenField Value='<%# Eval("SectionID") %>' ID="hidSectionID" runat="server" Visible="false"/>
        <optgroup label='<%# Eval("Name") %>'>

            <asp:Repeater ID="rptIssuesInSection" runat="server" DataSourceID="sdsIssuesInSection">
                    <option value='<%# Eval("IssueID") %>'><%# (Eval("Problem").ToString().Length > 100 ? Eval("Problem").ToString().Substring(0, 100) + "..." : Eval("Problem")) %></option>

the code it produces is something like (picture this as a drop down list with groups):

+ Section 1 +
   Item A
   Item B
+ Section 2 +
   Item C
   Item D

whichever item my user selects, i need to get the value of that selected item. trying to use FindControl inside my "add to release" button event produces a null control.

System.Web.UI.HtmlControls.HtmlSelect ddlIssuesNotInRelease = (System.Web.UI.HtmlControls.HtmlSelect)rptIssuesNotInRelease.FindControl("ddlIssuesNotInRelease");

what i am missing? how can i access the value of my drop down list during my button click event? am i creating optgroups with asp all wrong?
Old September 12th, 2006, 09:01 AM
Friend of Wrox
Join Date: Feb 2006
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts

The reason you can not find this control on the server side is that you have used a server side control (a repeater) to simply print out a client side select box to the client tier. You named that client side select box "ddlIssuesNotInRelease" but in reality there is no "ddlIssuesNotInRelease" control on the server, thus there is nothing for that select box to post back to. ddlIssuesNotInRelease only exists in the client tier as you have it now.

I am pretty sure you don't want to be using a repeater to do this. I am not quite sure what to recommend but you definitely need to use a server side control if you need to post back and access the control on the server side.

Neil Timmerman
Veris Consulting
Old September 15th, 2006, 09:52 AM
Registered User
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

while that's not the answer i was hoping for, it's the answer i feared i'd get. "Connect" from the asp forums [1] was able to point me to a different way of getting optgroups into my page while still being able to access the value of the select. perhaps someone else will find it useful.

thanks very much for the reply. :) maybe i'll be more fortunate in asp 3.

[1] http://forums.asp.net/thread/1395549.aspx

Similar Threads
Thread Thread Starter Forum Replies Last Post
nested <div> creates extra space sstuber BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 May 2nd, 2008 09:56 AM
syntax error on <option selected="selected"> hamid HTML Code Clinic 1 October 13th, 2004 09:20 AM
HELP: XSL -> HTML <select selected=true> jedbartlett XSLT 4 October 7th, 2004 11:16 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.