首页 > 开发 > 综合 > 正文

如何利用RowFilter 属性从一个dataset中创建两个不同的datagrid

2024-07-21 02:16:52
字体:
来源:转载
供稿:网友
women
nameagegenderstaci 22 f niki 21 f candy 44 f erica 32 f andrea 23 f susan 36 f
men
nameagegenderalex 24 m john 39 m chad 23 m greg 48 m

<%@ 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>


  • 网站运营seo文章大全
  • 提供全面的站长运营经验及seo技术!
  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表