Basic No-Code GridView

Posted by David Wier on 03/26/10 | Code Samples

Sometimes, all you really need to do is to show your data (received from a database, etc) on a page - that's all. With ASP.Net 2.0, it is extremely easy now. All you need is a GridView control and a DataSource Control. The DataSource control's properties get populated with all the connection information, and the DataSourceID property of the DataGrid references the DataSource Control. There is absolutely no code necessary. From that point on, you can get as complicated as you like. This particular sample uses a SQLDataSourceControl, pointing to the Customers Table of the Northwind Database.

<html>
    <head>
        <meta name="GENERATOR" Content="ASP Express 4.5">
        <title>Basic No-Code GridView</title>
</head>
    <body>
        <form id="form1" Runat="server">
            <div align="center">
                <asp:Label ID="label1" ForeColor="Blue" Font-Bold="True" Runat="server" /> 
                <asp:GridView Runat="server"
                    Id="gvPublishers"
                    GridLines="Both"
                    cellpadding="0"
                    cellspacing="0"
                    Headerstyle-BackColor="#BDCFE7"
                    Headerstyle-Font-Name="Arial"
                    Headerstyle-Font-Size="12"
                    BackColor="#E7EFFF"
                    Font-Name="Arial"
                    Font-Size="10"
                    BorderColor="Black"
                    DataSourceID="SQLDS1"
                    AutogenerateColumns="True"> 
            </asp:GridView>
        </div>
    <asp:SQLDataSource ID="SQLDS1" 
        ConnectionString="<%$ ConnectionStrings:YourConnStringGoesHere %>"
        SelectCommand="Select Top 10 CustomerID, CompanyName, ContactName from Customers" Runat="Server">
        </asp:SQLDataSource> 
        </form>
    </body>
</html>    



























































































0 Comments

COMMENTS

Name:
URL:
Comment:

Comments are disabled for this article.