ASP.NET - How to get RowID from dynamic table in ASP.NET (C#)?

Asked By Sivanesh Vanmeeganathan on 20-Jun-12 01:04 AM
Earn up to 10 extra points for answering this tough question.
Here i am using like this,

Panel1.Controls.Clear();
      Table tbl = new Table();
      Panel1.Controls.Add(tbl);
      int count = 0;

      connection1.Open();
      SqlCommand cmd11 = new SqlCommand("select * from product_config where submenu='59'", connection1);
      SqlDataReader sdr11 = cmd11.ExecuteReader();
      while (sdr11.Read())
      {
        TableRow tr1 = new TableRow();
        int ii = sdr11.FieldCount;
        for (int li = 0; li < ii; li++)
        {
          if (sdr11[li].ToString() != "")
          {
            TableCell tc = new TableCell();
            chkBox = new CheckBox();
            chkBox.CheckedChanged += new EventHandler(chkBox_CheckedChanged);
            chkBox.AutoPostBack = true;
            chkBox.ID = "chk" + sdr11[li].ToString() + li + count;
            chkBox.Text = sdr11[li].ToString();
            tc.Controls.Add(chkBox);
            tr1.Cells.Add(tc);
          }
          else
          {
            TableCell tc = new TableCell();
            Label txtBox = new Label();
            tc.Controls.Add(txtBox);
            tr1.Cells.Add(tc);
          }
        }
        tbl.Rows.Add(tr1);
        count++;
      }
      sdr11.Close();
      connection1.Close();

But i cannot find checkbox checked rowid then only i get that rows checkbox text details

Kindly give me solution for get RowID
[)ia6l0 iii replied to Sivanesh Vanmeeganathan on 20-Jun-12 09:43 PM
I believe you have one checkbox per TableRow. So, your checkbox in dynamic row, should be created with an ID like this,
chkBox.ID = string.Format("chk{0}", count); 

If you want some other ID, then let us know how your code determines a different ID for the checkbox. 

Hope this helps.