<%@ page language="vb" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<script runat="server">
sub page_load(sender as object, e as eventargs)
dim myconnection as new sqlconnection(configurationsettings.appsettings("dsn_aspa"))
dim myadapter as new sqldataadapter("select personname,personage,persongender from tblpeople", myconnection)
dim mydataset as new dataset()
try
myadapter.fill(mydataset, "people")
dim mydataview as dataview = mydataset.tables("people").defaultview
mydataview.rowfilter = "persongender='f'"
myfemaledatagrid.datasource = mydataview
myfemaledatagrid.databind()
mydataview.rowfilter = "persongender='m'"
mymaledatagrid.datasource = mydataview
mymaledatagrid.databind()
catch myexception as exception
response.write("an error has occurred: " & myexception.tostring())
end try
end sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
women<br>
<asp:datagrid id="myfemaledatagrid" runat="server" autogeneratecolumns="false" enableviewstate="false">
<columns>
<asp:templatecolumn headertext="name">
<itemtemplate>
<span><%# container.dataitem("personname") %></span>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext="age">
<itemtemplate>
<span><%# container.dataitem("personage") %></span>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext="gender">
<itemtemplate>
<span><%# container.dataitem("persongender") %></span>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</p>
<p>
men<br>
<asp:datagrid id="mymaledatagrid" runat="server" autogeneratecolumns="false" enableviewstate="false">
<columns>
<asp:templatecolumn headertext="name">
<itemtemplate>
<span><%# container.dataitem("personname") %></span>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext="age">
<itemtemplate>
<span><%# container.dataitem("personage") %></span>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn headertext="gender">
<itemtemplate>
<span><%# container.dataitem("persongender") %></span>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</p>
</form>
</body>
</html>
新闻热点
疑难解答