会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
蓝狐的技术思考 BlueFox Thinking in Tech...
交流,分享,探讨技术...... Communication, Sharing, and Discussion about Technology.....
导航
博客园
首页
新随笔
联系
订阅
管理
公告
在Repeater中动态添加服务器端(按钮)控件
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
True
"
%>
<
html
>
<
head
>
<
script
language
="C#"
runat
="server"
>
void
Page_Load(Object Sender, EventArgs e)
{
if
(
!
IsPostBack)
{
ArrayList values
=
new
ArrayList();
values.Add(
new
PositionData(
"
Microsoft
"
,
"
Msft
"
));
values.Add(
new
PositionData(
"
Intel
"
,
"
Intc
"
));
values.Add(
new
PositionData(
"
Dell
"
,
"
Dell
"
));
Repeater1.DataSource
=
values;
Repeater1.DataBind();
}
}
void
R1_ItemCommand(Object Sender, RepeaterCommandEventArgs e)
{
Label2.Text
=
"
The
"
+
((Button)e.CommandSource).Text
+
"
button has just been clicked; <br>
"
;
}
public class PositionData
{
private string name;
private string ticker;
public PositionData(string name, string ticker)
{
this
.name
=
name;
this
.ticker
=
ticker;
}
public string Name
{
get
{
return
name;
}
}
public string Ticker
{
get
{
return
ticker;
}
}
}
</
script
>
</
head
>
<
body
>
<
h3
>
Repeater Example
</
h3
>
<
form
id
="Form1"
runat
=server
>
<
b
>
Repeater1:
</
b
>
<
p
>
<
asp:Repeater
id
=Repeater1
OnItemCommand
="R1_ItemCommand"
runat
="server"
>
<
HeaderTemplate
>
<
table
border
=1
>
<
tr
>
<
td
><
b
>
Company
</
b
></
td
>
<
td
><
b
>
Symbol
</
b
></
td
>
</
tr
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
tr
>
<
td
>
<%
# DataBinder.Eval(Container.DataItem,
"
Name
"
)
%>
</
td
>
<
td
>
<
ASP:Button
ID
="Button1"
Text
=<%#
DataBinder.Eval(Container.DataItem, "Ticker") %
>
runat="server" />
</
td
>
</
tr
>
</
ItemTemplate
>
<
FooterTemplate
>
</
table
>
</
FooterTemplate
>
</
asp:Repeater
>
<
p
>
<
asp:Label
id
=Label2
font-name
="Verdana"
ForeColor
="Green"
font-size
="10pt"
runat
="server"
/>
</
form
>
</
body
>
</
html
>
posted on
2007-03-16 10:29
蓝狐
阅读(
935
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部