473,671 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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$ContentPl aceHolder1$rptO ptions$ctl01$dl Options

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

I thought it would be something like this:

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

But I just can't get the syntax right.

Thanks

Jack

Feb 18 '06 #1
3 2792
Try

foreach (RepeaterItem item in rptOptions.Item s)
{
DropDownList b = (DropDownList)i tem.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$ContentPl aceHolder1$rptO ptions$ctl01$dl Options

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

I thought it would be something like this:

foreach (RepeaterItem item in rptOptions.Item s)
{
DropDownList b = (DropDownList)i tem.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$ContentPl aceHolder1$rptO ptions$ctl01$dl Options 4
ctl00$ContentPl aceHolder1$rptO ptions$ctl02$dl Options 1

So the values are getting through. I tried this:

Repeater rpt =
(Repeater)Page. PreviousPage.Fi ndControl("ctl0 0").FindControl ("ContentPlaceH older1").FindCo ntrol("dlOption s");

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.Fi ndControl("ctl0 0").FindControl ("ContentPlaceH older1").FindCo ntrol("rptOptio ns");

DropDownList ddl =
(DropDownList)r pt.FindControl( "ctl01").FindCo ntrol("dlOption s");
Response.Write( "Here it is:" + ddl.SelectedIte m.Value.ToStrin g());

However, when I try to do this:

foreach (RepeaterItem item in rpt)
{
DropDownList b = (DropDownList)i tem.FindControl ("dlOptions" );
Response.Write( ddl.SelectedIte m.Value.ToStrin g()); + "<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
7653
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 alright. However with these repeating columns it throws everything out of align because it lets you scroll horizontally but everything else on the page stops where the original right side was. Is there a way it can be set up so that you say repeat...
6
1329
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 string ticker;
0
1171
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 tables (approx 5-10 rows by 3-4 columns) of data using repeaters nested in a datalist. Each row in the datalist source will act as a pointer and filter to the child table for the repeater source.
5
3765
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...: <asp:datalist id="DataList1" runat="server"> <HeaderTemplate> <table border="0" cellpadding="0" cellspacing="0" width="400"> <tr> <td width="100">First Name</td>
2
1147
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...) My experience with datalists is that you can have a <SeparatorTemplate> between each row, but how do they manage to separate rows at random intervals?
1
1743
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 id="tdDepartment" runat="server"><asp:datalist id="dlstDept" runat="server" HorizontalAlign="Left" CellPadding="0" Width="100%"> <HeaderTemplate> <p><b>Department Info</b></p> </HeaderTemplate> <ItemTemplate>
3
1420
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" RepeatDirection="Vertical" OnItemDataBound="dlChapter_OnItemDataBound"> <ItemTemplate> <table> <tr> <td colspan="2"><%# DataBinder.Eval(Container.DataItem, "ChapterName")%></td>
3
8885
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 mouse is moved over a row: <script runat="server"> Sub CreateItem(ByVal obj As Object, ByVal ea As DataListItemEventArgs) If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType = ListItemType.AlternatingItem) Then
2
11836
by: Paulo | last post by:
What is DetailsView, FormView, DataList, Repeater components? Any differences? VS 2005 asp.net C#
0
8485
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8403
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8828
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8677
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7446
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5704
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.