I have a very simple page which uses jqueryui to create a couple of tabs.
Tab1 is for data entry. Really simple, a couple of text boxes, a dropdown list and a few buttons. It performs a sort on the data entered and bungs it into an SQL table.
Tab2 generates a table in the format
checkbox id sortdir data timetaken
This is generated dynamically like this
Expand|Select|Wrap|Line Numbers
- private void generateTable()
- {
- long timer = 0;
- int sort = 0;
- string data = "";
- SqlConnection sql = connect();
- SqlDataReader sqlr = null;
- for (int n = 1; n < getRows() + 1; ++n)
- {
- TableRow tRow = new TableRow();
- Table1.Rows.Add(tRow);
- using (SqlCommand sqlc = sql.CreateCommand())
- {
- sqlc.CommandType = CommandType.StoredProcedure;
- sqlc.Parameters.AddWithValue("@ID", n);
- sqlc.CommandText = "spReadData";
- sql.Open();
- sqlr = sqlc.ExecuteReader();
- if (sqlr.Read())
- {
- timer = (long)sqlr["timetaken"];
- sort = (int)sqlr["sortedby"];
- data = (string)sqlr["sortedvalues"];
- }
- TableCell check = new TableCell();
- tRow.Cells.Add(check);
- System.Web.UI.WebControls.CheckBox cb = new CheckBox();
- cb.ID = n.ToString();
- check.Controls.Add(cb);
- for (int g = 0; g < 4; g++)
- {
- TableCell cell = new TableCell();
- tRow.Cells.Add(cell);
- System.Web.UI.WebControls.Label lbl = new Label();
- switch (g)
- {
- case 0:
- lbl.Text = n.ToString();
- break;
- case 1:
- lbl.Text = timer.ToString();
- break;
- case 2:
- lbl.Text = sort == 0 ? "Ascending" : "Decending";
- break;
- case 3:
- lbl.Text = data;
- break;
- }
- cell.Controls.Add(lbl);
- }
- sql.Close();
- }
- }
- }
Problem is this. The checkboxes are to be used to select if the output is to be put into an XML file for export. I could add an event to each checkbox to store/remove from a list but I'd rather not.
The code I have to parse the checkboxes though isn't a happy beast - it's simply not picking them up (checked using the debugger in VS2010)
Expand|Select|Wrap|Line Numbers
- private void exportXML(object s, EventArgs e)
- {
- List<int> ids = new List<int>();
- long tt;
- int dir;
- string data;
- int n = 0;
- foreach (Control ctrl in this.Controls)
- {
- if (ctrl is CheckBox)
- {
- if (((CheckBox)ctrl).Checked == true)
- ids.Insert(n++, Convert.ToInt32(((CheckBox)ctrl).ID));
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- if (ctrl is CheckBox)
The event is only fired off on the tab with the dynamic table on it.
Any clues on why this is failing?
Paul