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
- //page.aspx
- <asp:table ID="tbl" runat="server" />
- //page.aspx.cs
- protected void Page_Load(object sender, EventArgs e)
- {
- //Add each row to the table
- foreach(TableRow row in CreateTable())
- {
- tbl.Rows.Add(row);
- }
- }
- private List<TableRow> CreateTable()
- {
- //Create the row collection
- List<TableRow> rowCollection = new List<TableRow>();
- //Create the table rows
- TableRow tblRowRateLabel = new TableRow();
- TableRow tblRowRate = new TableRow();
- //Create the cells
- TableCell tblCellRateLabel = new TableCell();
- TableCell tblCellRate = new TableCell();
- //Add the data to the cells
- //Create the text and add to cell
- tblCellRateLable.Controls.Add(new LiteralControl("Rate"));
- //Create the drop down list
- DropDownList ddlRating = new DropDownList();
- for(int i = 0; i < 5; i++)
- {
- ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString);
- ddlRating.Items.Add(item);
- }
- //Create the button
- Button btnRate = new Button();
- btnRate.Text = "Rate";
- btnRate.Command += new CommandEventHandler(ProcessRating);
- //Add button and list to the cell
- tblCellRate.Controls.Add(ddlRating);
- tblCellRate.Controls.Add(btnRate);
- //Add the cells to the rows
- tblRowRateLabel.Cells.Add(tblCellRateLabel);
- tblRowRate.Cells.Add(tblCellRate);
- //Add the rows to the rowCollection
- rowCollection.Add(tblRowRateLabel);
- rowCollection.Add(tblRowRate);
- //Return the row collection
- return rowCollection
- }
- public void ProcessRating(object o, CommandEventArgs e)
- {
- //HELP - What do I do here?
- }
Thanks