GridView width DetailsView (widthin two webforms) using SQLDataSource

Create an ASP.NET website. Under the website create a folder named "GridViewWidthDetailsView". Under the folder create two webforms named "Test02A" and "Test02B".

Database is "Northwind". Used table is "Products".

Result:

Test02A Page

Test02B Page

Test02A.aspx

==========

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test02A.aspx.cs" Inherits="GridViewWidthDetailsView_Test02A" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataKeyNames="ProductID" DataSourceID="SqlDataSource1" AllowPaging="true" PageSize="5">
            <Columns>
                <asp:BoundField DataField="ProductID" HeaderText="ProductID"
                    InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
                <asp:BoundField DataField="ProductName" HeaderText="ProductName"
                    SortExpression="ProductName" />
                <asp:HyperLinkField HeaderText="UnitPrice" DataTextField="UnitPrice" DataNavigateUrlFields="ProductID"
                    DataNavigateUrlFormatString="Test02B.aspx?id={0}" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [ProductID], [ProductName],[UnitPrice] FROM [Products]">
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

============================================================================================

Test02B.aspx

=========

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test02B.aspx.cs" Inherits="GridViewWidthDetailsView_Test02B" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
            DataKeyNames="ProductID" DataSourceID="SqlDataSource1">
            <Fields>
                <asp:BoundField DataField="ProductID" HeaderText="ProductID"
                    InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
                <asp:BoundField DataField="ProductName" HeaderText="ProductName"
                    SortExpression="ProductName" />
                <asp:BoundField DataField="SupplierID" HeaderText="SupplierID"
                    SortExpression="SupplierID" />
                <asp:BoundField DataField="CategoryID" HeaderText="CategoryID"
                    SortExpression="CategoryID" />
                <asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit"
                    SortExpression="QuantityPerUnit" />
                <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice"
                    SortExpression="UnitPrice" />
                <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock"
                    SortExpression="UnitsInStock" />
                <asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder"
                    SortExpression="UnitsOnOrder" />
                <asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel"
                    SortExpression="ReorderLevel" />
                <asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued"
                    SortExpression="Discontinued" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT * FROM [Products] WHERE ([ProductID]=@ProductID)">
            <SelectParameters>
                <asp:QueryStringParameter Name="ProductID" QueryStringField="id" />
            </SelectParameters>
        </asp:SqlDataSource>
        <a href="javascript:history.back()">BACK</a>
    </div>
    </form>
</body>
</html>

posted @ 2009-01-09 18:06  OOK  阅读(184)  评论(0编辑  收藏  举报