Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

i have a web form in which i took a asp.net panel

now at run time i make a table whose id is td

add rows and cells at runtime

now on button click i have to find out table in panel

but im not able to find out

the code for create table is
try
            {
                //Panel1.Controls.Add(new LiteralControl("<table id="as">"));
                Table td=new Table();
                td.ID = "td";
         
                TableRow tr;
                TableCell tc;
                TableCell tc2;
                TableCell tc3;
                int counter = GridView1.Rows.Count;
                for (int i = 0; i < counter; i++)
                {
                    CheckBox cb = ((CheckBox)(GridView1.Rows[i].Cells[0].FindControl("CheckBox1")));
                    Label lb1 = ((Label)(GridView1.Rows[i].Cells[1].FindControl("label1")));
                    Label lb2 = ((Label)(GridView1.Rows[i].Cells[2].FindControl("label2")));
                    Label lb3 = ((Label)(GridView1.Rows[i].Cells[3].FindControl("label3")));
                    Label lb4 = ((Label)(GridView1.Rows[i].Cells[4].FindControl("label4")));
                    
                    if (cb.Checked == true)
                    {
                       tr=new TableRow();
                        //Panel1.control
                     tc=new TableCell();
                        Label lb = null;
                        lb = new Label();
                        lb.ID = "lb" + i.ToString();
                        lb.Text = lb1.Text;
                        tc.Controls.Add(lb);
                        tr.Controls.Add(tc);
                        tc2 = new TableCell();
                       // this.Panel1.Controls.Add(lb);
                       // Panel1.Controls.Add(new LiteralControl("    "));
                        string sdf = (lb2.Text +" "+ lb3.Text +" "+ lb4.Text).ToString();
                        Label lb5 = null;
                        lb5 = new Label();
                        lb5.ID = "lb" + i.ToString();
                        lb5.Text = sdf;
                        tc2.Controls.Add(lb5);
                        tr.Controls.Add(tc2);
                       // this.Panel1.Controls.Add(lb5);
                        //Panel1.Controls.Add(new LiteralControl("    "));
                       TextBox tb = null;
                            tb = new TextBox();
                            tb.ID = "txt" + i.ToString();
                            tc3 = new TableCell();
                            tc3.Controls.Add(tb);
                            tr.Controls.Add(tc3);
                            td.Rows.Add(tr);
                            //this.Panel1.Controls.Add(tb);
                    //        Panel1.Controls.Add(new LiteralControl("<br>"));
                      //      Panel1.Controls.Add(new LiteralControl("<br>"));  
                    }
                    else
                    {
                    }

                }
                Panel1.Controls.Add(td);
            }
            catch (Exception re)
            {
                Response.Write("<script language='javascript'>alert('" + re.Message + "');</script>");
            }
            finally
            {
            }
</br></br></table>


and for find out table in panel is

if (Panel1.Controls.Count == 0)
            {

            }
            else
            {
                Table tf = (Table)this.Panel1.FindControl("td"); 
                int counter = tf.Rows.Count;
                for (int i = 0; i < counter; i++)
                {

                }

}


any idea thanks in advance
Posted
Updated 27-Apr-11 0:01am
v2

According to me, the id og controls must be different than the html tag names.

Just try changing it and see if it helps..
 
Share this answer
 
Well just change your table name from "td" to some other name .....

The reason behind is that might be "td" is pre-define name which is nothing but "Table Data" same what we have used while creating Table.

Just change it see if it helps ....
 
Share this answer
 
Comments
sharmarun 27-Apr-11 7:05am    
k
sharmarun 27-Apr-11 7:39am    
no its still not working

i still got tf value null
sharmarun 27-Apr-11 7:48am    
any suggesion

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900