请问有没有办法动态添加一个组件到WEB FROM上

chenhaipeng 2003-07-20 06:41:30
比喻说添加一个System.Web.UI.WebControls.Button到WebForm, 最好能够指定位置(left, top), 有没有办法实现呢?
...全文
84 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenhaipeng 2003-07-22
  • 打赏
  • 举报
回复
我其实是想通过代码来控制对象的位置(left, top), 难道没能办法吗?
chenhaipeng 2003-07-22
  • 打赏
  • 举报
回复
up
Coder李海波 2003-07-21
  • 打赏
  • 举报
回复
protected System.Web.UI.WebControls.Table Table1;

private void Page_Load(object sender, System.EventArgs e)
{
string[] n = new String[5];
n[0] = "hehe";
n[1] = "heihei";
n[2] = "hengheng";
n[3] = "kao";
n[4] = "faint";
for(int i=0;i<n.Length;i++)
{
Button bt = new Button();
bt.Width = 100;
bt.ID = n[i];
bt.Text = n[i];
//添加事件
//bt.Attributes.Add("onclick","return NeedHelp();");
int cellIndex = i%3;
int rowIndex = i/3;
if(cellIndex==0)
{
TableRow row = new TableRow();
Table1.Rows.Add(row);
}
TableCell cell = new TableCell();
TableRow currentRow = Table1.Rows[rowIndex];
cell.Controls.Add(bt);
currentRow.Cells.Add(cell);
}
}
chenhaipeng 2003-07-21
  • 打赏
  • 举报
回复
请继续
YOURSUN2008 2003-07-21
  • 打赏
  • 举报
回复
参照自动生成的初始化代码
chenhaipeng 2003-07-21
  • 打赏
  • 举报
回复
使用如下代码并不能添加成功, 请继续:
Button newbutton = new Button();
newbutton.ID = "aaa";
newbutton.Text = "AAA";
Page.Controls.Add(newbutton);
panyee 2003-07-20
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1945/1945697.xml?temp=.2097437

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧