在面板中找到控件 [英] find control in panel

查看:77
本文介绍了在面板中找到控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个Web表单,其中使用了一个asp.net面板

现在在运行时,我创建一个表,其ID为td

在运行时添加行和单元格

现在单击按钮,我必须在面板中查找表

但我无法找出

创建表的代码是

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

推荐答案

据我说,id og控件必须与html标记名称不同.

只需尝试更改它,看看是否有帮助..
According to me, the id og controls must be different than the html tag names.

Just try changing it and see if it helps..


好吧,只需将表名从"td"更改为其他名称.....

其背后的原因是"td"可能是预定义名称,除了创建表时所使用的表数据"外,别无其他.

只需更改它,看看是否有帮助....
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 ....


这篇关于在面板中找到控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆