选择显示字体大小

buttoncolumn


boundcolumn 最主要的功能是利用linkbutton 或pushbutton 来显示数据源中的一个字段内容,并且可以触发datagrid web 控件的事件。其使用语法如下所示:

<asp:buttoncolumn
buttontype=&quot;linkbutton pushbutton&quot;
commandname=&quot;命令名称&quot;
datatextfield=&quot;datasourcefield&quot;
datatextformatstring=&quot;formatstring&quot;
footertext=&quot;footertext&quot;
headerimageurl=&quot;url&quot;
headertext=&quot;headertext&quot;
readonly=&quot;true false&quot;
sortfield=&quot;datasourcefieldtosortby&quot;
text=&quot;buttoncaption&quot;
visible=&quot;true false&quot;
/>

其中除了共同基础属性以及样式对象外,常用的属性如下表所示:

下列程序代码范例以boundcolumn 来显示字段内容,并且显示使用者点选了哪一笔记录:

<%@import namespace=system.data.ado%>
<%@import namespace=system.data%>
<!--#include file=&quot;gettable.inc&quot;-->
<html>
<form runat=&quot;server&quot;>
<asp:datagrid id=&quot;dga&quot; allowpaging=&quot;true&quot; pagesize=&quot;5&quot;
onpageindexchanged=&quot;dga_pagechg&quot; runat=&quot;server&quot;
pagerstyle-mode=&quot;numericpages&quot; bordercolor=&quot;#808080&quot;
headerstyle-font-names=&quot;courier new&quot;
headerstyle-backcolor=&quot;#d1dceb&quot;
headerstyle-font-bold=&quot;true&quot; headerstyle-horizontalalign=&quot;center&quot;
autogeneratecolumns=&quot;false&quot;
onitemcommand=&quot;dga_icmd&quot;>
<property name=&quot;columns&quot;>
<asp: buttoncolumn
headertext=&quot;姓名&quot;
datatextfield=&quot;username&quot;/>
<asp:boundcolumn
headertext=&quot;电话&quot;
datafield=&quot;usertel&quot;/>
<asp:boundcolumn
headertext=&quot;住址&quot;
datafield=&quot;useradd&quot;/>
</property>
</asp:datagrid>
</form>
<asp:label id=&quot;label1&quot; runat=&quot;server&quot;/>
<script language=&quot;vb&quot; runat=&quot;server&quot;>
sub page_load(sender as object, e as eventargs)
if page.ispostback=false then
dim dtdatatable as datatable=gettable(&quot;ch08\myweb.mdb&quot;, &quot;members&quot;)
dga.datasource=dtdatatable.defaultview
page.databind()
end if
label1.text=&quot;您目前没有点选任何记录.&quot;
end sub
sub dga_pagechg(sender as object, e as datagridpagechangedeventargs)
dim dtdatatable as datatable=gettable(&quot;ch08\myweb.mdb&quot;, &quot;members&quot;)
dga.datasource=dtdatatable.defaultview
page.databind()
end sub
sub dga_icmd(sender as object, e as datagridcommandeventargs)
dim shtrow as short= e.item.itemindex+1
if shtrow<>0 then
label1.text=&quot;您点选了第&quot; & shtrow.tostring() & _
&quot; 个字段的数据, 这<br>笔数据在数据源中是第&quot;
label1.text+=((dga.currentpageindex * dga.pagesize) +
shtrow).tostring & _
&quot;笔记录.&quot;
end if
end sub
</script>
</html>


上述范例我们指定datagrid web 控件的onitemcommand 属性为dga_icmd,表示按下显示使用者名称的buttoncolumn 时会触发dga_ccmd 事件,并且执行dga_icmd 事件程序;如下程序代码片段所示:

sub dga_icmd(sender as object, e as datagridcommandeventargs)
dim shtrow as short= e.item.itemindex+1
if shtrow<>0 then
label1.text=&quot;您点选了第&quot; & shtrow.tostring() & _
&quot; 个字段的数据, 这<br>笔数据在数据源中是第&quot;
label1.text+=((dga.currentpageindex * dga.pagesize) +
shtrow).tostring & _
&quot;笔记录.&quot;
end if
end sub

在这个事件程序中,我们利用e.item.itemindex 属性取得使用者点选了第几个项目的index 值;由于index 由0 开始,所以我们加上1 表示点选了第几个项目。如果没有任何项目被点选,则e.item.itemindex 属性传回-1。由于变量shtrow 为e.item.itemindex 加1 的结果,所以我们藉由判断变量shtrow 是否为0 来得知使用者是否有选择选项。
因为e.item.itemindex 属性传回的是使用者在datagrid web 控件上所点选的项目,并不是记录在数据源的地址;所以我们透过计算目前的页数索引乘以每页的纪录笔数后,再加上目前所在的字段即可得到该笔数据在数据源中的实际地址。所以使用者若点选了第六页的第四个字段,表达式则为(5*5)+4,结果29 就是记录在数据源的实际顺序。

若要取得该笔记录在数据源中的索引值,由于index 值是由0 开始计数,所以只要再减去1 即可。   


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

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   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons