Creating a master/detail page using gridview in asp.net

Creating a master/Detail page using GridView
MasterDetailsPageExample.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>asp.net GridView example: a sample simple Master-Details page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" ForeColor="LightSlateGray" Font-Bold="true" Font-Size="X-Large">
            Master-Details Page Example
        </asp:Label>
        <br /><br />
        <asp:SqlDataSource 
            ID="SqlDataSource1"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT CategoryID, CategoryName, Description FROM Categories"
            >
        </asp:SqlDataSource>
        <asp:GridView 
            ID="GridView1"
            runat="server"
            DataSourceID="SqlDataSource1"
            AutoGenerateSelectButton="true"
            DataKeyNames="CategoryID"
            BackColor="HotPink"
            ForeColor="Snow"
            BorderColor="LightPink"
            HeaderStyle-BackColor="DarkOrange"
            >
            <SelectedRowStyle ForeColor="HotPink" BackColor="Snow" />
        </asp:GridView>
        <asp:SqlDataSource 
            ID="SqlDataSource2"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT ProductID, ProductName, UnitPrice FROM Products WHERE CategoryID=@CategoryID"
            >
            <SelectParameters>
                <asp:ControlParameter Name="CategoryID" ControlID="GridView1" PropertyName="SelectedDataKey.Value" />
            </SelectParameters>
        </asp:SqlDataSource>
        <br />
        <asp:Label 
            ID="Label2" 
            runat="server" 
            Text="Products in selected Category" 
            Font-Size="Large"
            ForeColor="LightSlateGray"
            >
        </asp:Label>
        <br />
        <asp:GridView 
            ID="GridView2"
            runat="server"
            DataSourceID="SqlDataSource2"
            AllowSorting="false"
            AllowPaging="true"
            PageSize="5"
            BackColor="SteelBlue"
            ForeColor="WhiteSmoke"
            >
        </asp:GridView>
    </div>
    </form>
</body>
</html>










Related asp.net examples