Pages

1 Aug 2013

Grid view Example : How to use gridview in asp.net

<%@ Page Language="C#" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
 
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>GridView example: how to use GridView in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"  
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID"  
            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"  
                    SortExpression="CustomerID" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName"  
                    SortExpression="CompanyName" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName"  
                    SortExpression="ContactName" />
                <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle"  
                    SortExpression="ContactTitle" />
                <asp:BoundField DataField="Address" HeaderText="Address"  
                    SortExpression="Address" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="Region" HeaderText="Region"  
                    SortExpression="Region" />
                <asp:BoundField DataField="PostalCode" HeaderText="PostalCode"  
                    SortExpression="PostalCode" />
                <asp:BoundField DataField="Country" HeaderText="Country"  
                    SortExpression="Country" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"  
            ConnectionString="<%$ ConnectionStrings:AppConnectionString1 %>"  
            SelectCommand="SELECT * FROM [Customers]"></asp:SqlDataSource>
     
    </div>
    </form>
</body>
</html>  

No comments:

Post a Comment