zoukankan
html css js c++ java
asp.net动态生成控件及访问控件
asp.net动态生成控件的方法:
1.在aspx页面放一个Panel控件
2.代码如下:
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
if
(Session[
"
p_userid
"
]
==
null
||
Session[
"
p_loginName
"
]
==
null
||
Session[
"
p_created
"
]
==
null
)
{
Response.Write(
"
<script>alert('请先登陆');location.href='../loginProc/login.aspx';</script>
"
);
Response.End();
}
else
{
Panel1.Controls.Add(
new
LiteralControl(
"
<table>
"
));
Panel1.Controls.Add(
new
LiteralControl(
"
\n
"
));
SqlCommand cmd
=
new
SqlCommand(
"
select infos.* from infos,infoGroups where infos.infoGroup_id = infoGroups.id and infoGroups.title='联系方式' order by infos.pri
"
,connPartner);
SqlDataAdapter da
=
new
SqlDataAdapter();
DataSet ds
=
new
DataSet();
da.SelectCommand
=
cmd;
da.Fill(ds,
"
infos
"
);
for
(
int
i
=
0
;i
<
ds.Tables[
0
].Rows.Count;i
++
)
{
Panel1.Controls.Add(
new
LiteralControl(
"
<tr>
"
));
TableCell cell
=
new
TableCell();
//
创建单元格,也就是第一列
cell.Text
=
ds.Tables[
0
].Rows[i][
"
title
"
].ToString();
//
设置单元格内的文本
Panel1.Controls.Add(cell);
Panel1.Controls.Add(
new
LiteralControl(
"
<td>
"
));
TextBox textBox
=
new
TextBox();
textBox.ID
=
"
t
"
+
ds.Tables[
0
].Rows[i][
"
id
"
].ToString();
Panel1.Controls.Add(textBox);
Panel1.Controls.Add(
new
LiteralControl(
"
</td>
"
));
Panel1.Controls.Add(
new
LiteralControl(
"
<td>
"
));
Label lb
=
new
Label();
lb.ID
=
"
l
"
+
ds.Tables[
0
].Rows[i][
"
id
"
].ToString();
lb.Text
=
"
"
+
ds.Tables[
0
].Rows[i][
"
tip
"
].ToString();
lb.CssClass
=
"
registerInfo
"
;
Panel1.Controls.Add(lb);
Panel1.Controls.Add(
new
LiteralControl(
"
</td>
"
));
Panel1.Controls.Add(
new
LiteralControl(
"
</tr>
"
));
Panel1.Controls.Add(
new
LiteralControl(
"
\n
"
));
}
Button rebt
=
new
Button();
rebt.ID
=
"
redirect
"
;
rebt.Text
=
"
不填了
"
;
rebt.Click
+=
new
EventHandler(rebt_Click);
Panel1.Controls.Add(rebt);
}
}
private
void
rebt_Click(
object
sender, EventArgs e)
{
Response.Redirect(
"
../partnerProc/default.html
"
);
}
访问动态生成控件,可以通过FindControl方法,代码如下:
for
(
int
i
=
0
;i
<
ds.Tables[
0
].Rows.Count;i
++
)
{
Label lb;
lb
=
(Label)Panel1.FindControl(
"
l
"
+
ds.Tables[
0
].Rows[i][
"
id
"
].ToString());
if
(lb
!=
null
)
{
lb.Text
=
"
"
+
ds.Tables[
0
].Rows[i][
"
tip
"
].ToString();
lb.CssClass
=
"
registerInfo
"
;
}
}
查看全文
相关阅读:
1、电源管理概念
37、mipg-streamer的使用讲解
ARM+linux学习过程(3)mini2440的USB驱动无法在win7下识别
ARM+linux学习过程(2)安装vmware-tool过程与错误解决
ARM+linux学习过程(1)虚拟机下ubuntu上网
35、在编译Linux内核中增加程序需要完成以下3项工作
36、ALSA声卡驱动和应用
35、在JZ2440上使用3G上网卡
POJ
CF453-A Visiting a Friend (dfs)
原文地址:https://www.cnblogs.com/nasdaqhe/p/563592.html
最新文章
UGUI Slider
Unity Unity发布的ios包在iphone上声音小的原因
Unity 为什么有时候播放音乐(音效)会没有声音
Unity [SerializeField]
UGUI RectTransform 矩形变换
Unity 去除场景中的雾效果
UnityError SocketException: 以一种访问权限不允许的方式做了一个访问套接字的尝试。
UGUI 切割图片
文件操作
初始函数
热门文章
函数的调用
函数进阶
闭包
匿名函数
装饰器
自定义模块
re模块
正则
u-boot分析1:Nandflash、Norflash启动
2、在uboot上实现电源管理
Copyright © 2011-2022 走看看