<%@ control language="vb" %>
<font face="verdana" color="green" size="2"><b>id: </b>
<%# databinder.eval(ctype(container, datalistitem).dataitem, "id") %>
<b>name: </b>
<%# databinder.eval(ctype(container, datalistitem).dataitem, "name") %>
<br>
<b>address: </b>
<%# databinder.eval(ctype(container, datalistitem).dataitem, "address") %>
<p>
</font>
最后,我们开始创建应用程序,新建一个工程,添加两个按钮和一个datalist控件如下图
[img]http://soft.yesky.com/image20010518/141690.jpg[img]
之后创建一个binddatagrid的方法,将dataset绑定到datalist控件中去,代码如下:
private void binddatagrid()
{
dtset = db.getdataset();
datalist1.datasource = dtset.tables[0].defaultview;
datalist1.databind();
}
private void page_load(object sender, system.eventargs e)
{
if(!ispostback)
{
binddatagrid();
}
}
最后,分别为两个按钮的clcik事件添加代码,分别使用page.loadtemplate方法去加载我们已经写好的两套模版组中的模版,代码如下。
private void button1_click(object sender, system.eventargs e)
{
// load templates
datalist1.alternatingitemtemplate =
page.loadtemplate("altitemtempate.ascx");
datalist1.itemtemplate =page.loadtemplate("itemtemplate.ascx");
datalist1.headertemplate =page.loadtemplate("headtemplate.ascx");
datalist1.footertemplate = page.loadtemplate("foottemplate.ascx");
binddatagrid();
}
private void button2_click(object sender, system.eventargs e)
{
// load templates
datalist1.alternatingitemtemplate =page.loadtemplate("altitemtempate2.ascx");
datalist1.itemtemplate = page.loadtemplate("itemtemplate2.ascx");
datalist1.headertemplate = page.loadtemplate("headtemplate2.ascx");
datalist1.footertemplate = page.loadtemplate("foottemplate2.ascx");
binddatagrid();
}
运行效果如下两图,当点不同的按钮时,动态装载不同的模版风格。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器