首页 > 开发 > 综合 > 正文

怎样使用DataGrid控件

2024-07-21 02:25:39
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

[visual basic, c#, jscript] 下面的示例展示如何使用 datagrid 控件来显示数据源中的项。
[visual basic]
<%@ page language="vb" autoeventwireup="true" %>
<%@ import namespace="system.data" %>

<html>
<script language="vb" runat="server">
function createdatasource() as icollection
dim dt as new datatable()
dim dr as datarow

dt.columns.add(new datacolumn("integervalue", gettype(int32)))
dt.columns.add(new datacolumn("stringvalue", gettype(string)))
dt.columns.add(new datacolumn("currencyvalue", gettype(double)))

dim i as integer
for i = 0 to 8
dr = dt.newrow()

dr(0) = i
dr(1) = "item " + i.tostring()
dr(2) = 1.23 *(i + 1)

dt.rows.add(dr)
next i

dim dv as new dataview(dt)
return dv
end function 'createdatasource


sub page_load(sender as object, e as eventargs)

if not ispostback then
' load this data only once.
itemsgrid.datasource = createdatasource()
itemsgrid.databind()
end if
end sub 'page_load

</script>

<body>

<form runat=server>

<h3>datagrid example</h3>

<b>product list</b>

<asp:datagrid id="itemsgrid"
bordercolor="black"
borderwidth="1"
cellpadding="3"
autogeneratecolumns="true"
runat="server">

<headerstyle backcolor="#00aaaa">
</headerstyle>

</asp:datagrid>

</form>

</body>
</html>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表