An error has occurred: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied. at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) at System.Data.SqlClient.SqlConnection.Open() at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) at ASP.RowFilterDoubleGrid_aspx.Page_Load(Object Sender, EventArgs E) ASPAlliance.com : The #1 ASP.NET Developer Community : ASP.NET: Simple Custom DataGrid
ASPAlliance.com : The #1 Active Server Pages .NET Community The #1 ASP.NET Community
Search   Search

Subscribe   Subscribe

Powered by ORCSWeb Hosting


Site Stats


Powered By ASP.NET
 
Featured Sponsor

Featured Columnist


Featured Book
Microsoft ASP.NET Step by Step
Microsoft ASP.NET Step by Step

Find Prices


New! asp.netPRO

We publish our articles in the standard RSS format.

Powerful .NET Email Component

Code Sharing Software
Click here to return to my article index

This code snippet demonstrates how to use the RowFilter property to create two different DataGrids from one DataSet.

Live Example

Women

Men

Source

The code sample below uses a few best pratices you should understand and be aware of:
*The code below uses structured error handling techniques in the form of the Try...Catch statement. Go here to read more about the great new structured error handling we VBers now have.
*The code below also uses a connection string stored in a web.config configuration file. Go here to read more about the web.config configuration file and how it can be used to store application wide data.
*The code below also follows proper database resouce management per this best practice.

<%@ 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>
Related Articles:
Hiding Columns In A DataGrid
How to add a confirmation popup to a DataGrid
Adding dynamic content to a DataGrid Footer
 Copyright © 2000-2003 ASPAlliance.com  Page Rendered at 12/3/2008 2:36:12 AM