如何使用for循环可见面板控件 [英] how to visible panel control using the for loop
本文介绍了如何使用for循环可见面板控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i am anil ..我在按钮点击时可视面板控制面临问题..
im在块中传递一个int值..
我的代码是
< br $> b $ b
int block = Convert.ToInt32(Label4.Text);
for ( int i = 1 ; i < = block; i ++)
{
Panel rpt_panel = new Panel();
rpt_panel.ID = pnlblock + i.ToString();
rpt_panel.Visible = true ;
}
帮帮我PLZ ..
谢谢提前
解决方案
这些是 新 面板:因此关键字new
。
您不会将它们附加到任何Controls集合,因此您根本不显示它们。
仅仅创建一个控件是不够的:你需要将它添加到你的页面或表单...
这段代码看起来没问题,但我认为你需要在页面上添加这个面板,使用一些占位符或其他东西。
你的代码中的
我可以看到你从代码中生成一个控件,你需要将它添加到页面中。有一些方法可以添加控件到页面。
page.controls.add(panlel);
或者可能在面板或占位符内
您正在创建一个新面板并使其可见。
如果您已经有面板并希望将其显示,请使用:
面板rpt_panel = Page.FindControl( pnlblock + i.ToString());
hii all.
i am anil.. i m facing a problem while to visible panel control on button click..
i m passing a int value in block..
my code is
int block = Convert.ToInt32(Label4.Text);
for (int i = 1; i <= block; i++)
{
Panel rpt_panel = new Panel();
rpt_panel.ID = "pnlblock" + i.ToString();
rpt_panel.Visible = true;
}
help me plz..
thanks in advance
解决方案
Those are new panels: hence the keywordnew
.
You do not attach them to any Controls collection, and so you don't display them at all.
Just creating a control is not enough: you need to add it to your page or form as well...
this code looks okay but i think you need to add this panel on the page by using some place holder or something.
from your code i can see that you are generating a control from the code and you need to add it to the page . there are some methods by which you can add controls to the page.
page.controls.add(panlel);
or may be inside a panel or placeholder
You are creating a new panel and making it visible.
If you already have the panel and want to make it visible, then use:
Panel rpt_panel = Page.FindControl("pnlblock" + i.ToString());
这篇关于如何使用for循环可见面板控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文