473,489 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP.NET C# controls help

9 New Member
Hi,

I am dynamically creating a page that contains a table and within that table there is a drop down list and a button. The drop down list and button let the user rate something, so they select the rating from the list and click the button to rate.

I have a function that creates the cells, rows and other control and returns a list of table rows.

My problem is that as everything is dynamically created, i cant access the controls in the table.

Heres the code

Expand|Select|Wrap|Line Numbers
  1. //page.aspx
  2. <asp:table ID="tbl" runat="server" />
  3.  
  4. //page.aspx.cs
  5.  
  6. protected void Page_Load(object sender, EventArgs e)
  7. {
  8.    //Add each row to the table
  9.    foreach(TableRow row in CreateTable())
  10.    {
  11.       tbl.Rows.Add(row);
  12.    }
  13. }
  14.  
  15. private List<TableRow> CreateTable()
  16. {
  17.    //Create the row collection
  18.    List<TableRow> rowCollection = new List<TableRow>();
  19.  
  20.    //Create the table rows
  21.    TableRow tblRowRateLabel = new TableRow();
  22.    TableRow tblRowRate = new TableRow();
  23.  
  24.    //Create the cells
  25.    TableCell tblCellRateLabel = new TableCell();
  26.    TableCell tblCellRate = new TableCell();
  27.  
  28.    //Add the data to the cells
  29.    //Create the text and add to cell
  30.    tblCellRateLable.Controls.Add(new LiteralControl("Rate"));
  31.  
  32.    //Create the drop down list
  33.    DropDownList ddlRating = new DropDownList();
  34.    for(int i = 0; i < 5; i++)
  35.    {
  36.       ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString);
  37.       ddlRating.Items.Add(item);
  38.    }
  39.  
  40.    //Create the button
  41.    Button btnRate = new Button();
  42.    btnRate.Text = "Rate";
  43.    btnRate.Command += new CommandEventHandler(ProcessRating);
  44.  
  45.    //Add button and list to the cell
  46.    tblCellRate.Controls.Add(ddlRating);
  47.    tblCellRate.Controls.Add(btnRate);
  48.  
  49.    //Add the cells to the rows
  50.    tblRowRateLabel.Cells.Add(tblCellRateLabel);
  51.    tblRowRate.Cells.Add(tblCellRate);
  52.  
  53.    //Add the rows to the rowCollection
  54.    rowCollection.Add(tblRowRateLabel);
  55.    rowCollection.Add(tblRowRate);
  56.  
  57.    //Return the row collection
  58.    return rowCollection
  59. }
  60.  
  61. public void ProcessRating(object o, CommandEventArgs e)
  62. {
  63.    //HELP - What do I do here?
  64. }
  65.  
Can any one tell me how i can access the drop down list (ddlRating) when the button is clicked please

Thanks
Aug 31 '07 #1
1 999
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
have you tried the find control?

if not, try to put it as a request variable
Aug 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
3643
by: Chris Thunell | last post by:
I have created several grids dynamically and have added them to different HTML placeholders on a vb.net web form. The grids and controls within them come up and view beautifully when the web page...
2
2892
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
5
2385
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
2
2562
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
0
2384
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
12
1579
by: Bob Jones | last post by:
I have an odd business requirement and I think that the implementation is not correct in the terms of OOP development. Any help on the concepts would be very appreciated! We currently have a...
4
2666
by: TS | last post by:
Steven, i lost this message conversation from outlook express and made a post online (see last one on this page). Please answer it as it hasn't been yet. thanks The clientID of our controls...
0
1822
JimWu
by: JimWu | last post by:
I have some problems in my code. The stutiation illustrate as the followsing statement. I use two pages, one, named "upload.aspx", is including several general html input tag, whose type are...
32
2749
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
4
2445
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
0
7108
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,...
0
7142
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
7181
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...
1
4875
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...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
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 ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.