473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

accessing datalist in repeater

I have a form that is submitted to another page. The form contains a
variable number of dropdownlists within a repeater. When the form is
submitted, I need to access the values of each dropdownlist. I never
know how many dropdownlists will be present in advance.

Also, both the repeater and the dropdownlists are nested within other
controls:

ctl00$ContentPlaceHolder1$rptOptions$ctl01$dlOptio ns

So how can I access the dropdownlists? I am using PreviousPageType on
the page that the form is being posted to.

I thought it would be something like this:

foreach (RepeaterItem item in rptOptions.Items)
{
DropDownList b = (DropDownList)item.FindControl("dlOptions");
Response.Write(b.Text + "<br>");
}

But I just can't get the syntax right.

Thanks

Jack

Feb 18 '06 #1
3 2786
Try

foreach (RepeaterItem item in rptOptions.Items)
{
DropDownList b = (DropDownList)item.FindControl("dlOptions");
Response.Write(b.SelectedItem.Text + "<br>");
}

HTH
Elton Wang

"jj******@gmail.com" wrote:
I have a form that is submitted to another page. The form contains a
variable number of dropdownlists within a repeater. When the form is
submitted, I need to access the values of each dropdownlist. I never
know how many dropdownlists will be present in advance.

Also, both the repeater and the dropdownlists are nested within other
controls:

ctl00$ContentPlaceHolder1$rptOptions$ctl01$dlOptio ns

So how can I access the dropdownlists? I am using PreviousPageType on
the page that the form is being posted to.

I thought it would be something like this:

foreach (RepeaterItem item in rptOptions.Items)
{
DropDownList b = (DropDownList)item.FindControl("dlOptions");
Response.Write(b.Text + "<br>");
}

But I just can't get the syntax right.

Thanks

Jack

Feb 18 '06 #2
I guess the real issue is that I don't know the correct syntax to
access the repeater on the second page:

The trace of the form contents shows this:

ctl00$ContentPlaceHolder1$rptOptions$ctl01$dlOptio ns 4
ctl00$ContentPlaceHolder1$rptOptions$ctl02$dlOptio ns 1

So the values are getting through. I tried this:

Repeater rpt =
(Repeater)Page.PreviousPage.FindControl("ctl00").F indControl("ContentPlaceHolder1").FindControl("dlO ptions");

But I just get "Object reference not set to an instance of an object."

So how can I access those repeaters? Also, as I said before, the number
of repeaters varies.

Thanks

Feb 19 '06 #3
I am now able to access the values when I do this:

Repeater rpt =
(Repeater)Page.PreviousPage.FindControl("ctl00").F indControl("ContentPlaceHolder1").FindControl("rpt Options");

DropDownList ddl =
(DropDownList)rpt.FindControl("ctl01").FindControl ("dlOptions");
Response.Write("Here it is:" + ddl.SelectedItem.Value.ToString());

However, when I try to do this:

foreach (RepeaterItem item in rpt)
{
DropDownList b = (DropDownList)item.FindControl("dlOptions");
Response.Write(ddl.SelectedItem.Value.ToString()); + "<br>");
}

it chokes. Any ideas?

Thanks

Feb 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Gav | last post by:
Hi All, I have created a datalist using the repeatcolumns property to create multiple columns. I have tried to keep everythings width to 100% so that if the window is resized it still looks...
6
by: Thanh | last post by:
I created an ASP.NET project and dropped a DataList on the web form. I then wrote a simple class to return data: namespace Playing { public class PositionData { private string name; private...
0
by: Shun Duke | last post by:
I have working code allowing me to nest repeaters inside datalists using relations and child rows but this does not allow me to acheive my goal. What I want to be able to do is display small...
5
by: Ben Fidge | last post by:
I'm using DataList to present tabular data but am often having problems with some rows column alignment being out of synch with the rest of the rows. My DataList looks similar to this...: ...
2
by: Stimp | last post by:
I would like to produce something like: http://redwoodestates.co.uk/forrent.aspx It's either a datalist/repeater/datagrid, but it is broken up into sections ("1 bedroom", "2 bedroom", etc...)...
1
by: Simon Cheng | last post by:
When I tried to display data in datalist and repeater, the first data item always disappears in all datalist and repeaters in my web forms. The code I use for the html page is: <TD...
3
by: GD | last post by:
I'm using a DataList and a Repeater (nested in the DataList) to display a list of "Chapters" and "Documents" within the Chapters. <asp:DataList ID="dlChapter" Runat="server" RepeatColumns="2"...
3
by: rn5a | last post by:
I want to change the background color of a row in a DataList when the mouse is moved over a row. This is how I tried but it doesn't change the background color of a row in the DataList when the...
2
by: Paulo | last post by:
What is DetailsView, FormView, DataList, Repeater components? Any differences? VS 2005 asp.net C#
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.