科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道应用软件组合ASP.NET 2.0数据控件构建强大用户接口

组合ASP.NET 2.0数据控件构建强大用户接口

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

本文,我将结合这几个数据控件对GridView控件做一个详细的介绍,使用户能够对每个数据行获得一个详细的了解。

作者:builder.com.cn 2007年4月2日

关键字:

  • 评论
  • 分享微博
  • 分享邮件
<%@ Page Language="C#" %>
<html>
<head id="Head1" runat="server">
<title>Master-Detail Page Example</title>
</head><body>
<form id="frmMasterDetail" runat="server">
<b>Select a city:</b>
<asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSource2" AutoPostBack="true"
DataTextField="City" runat="server" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" SelectCommand="SELECT DISTINCT City FROM Employees"
ConnectionString="Server=localhost;Database=Northwind;Trusted_Connection=true" />
<asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" runat="server"
DataSourceID="SqlDataSource1" DataKeyNames="EmployeeID"
AutoGenerateColumns="False" Width="427px" PageSize="10" BackColor="#c0c0c0"
BorderColor="black" BorderStyle="Groove" BorderWidth="5" Caption="GridView Example">
<SelectedRowStyleBackColor="yellow" />
<Columns>
<asp:CommandFieldShowSelectButton="True" />
<asp:BoundFieldDataField="EmployeeID" HeaderText="ID" ReadOnly="True" SortExpression="EmployeeID" />
<asp:BoundFieldDataField="LastName" HeaderText="Last" SortExpression="LastName" />
<asp:BoundFieldDataField="FirstName" HeaderText="First" SortExpression="FirstName" />
<asp:BoundFieldDataField="Region" HeaderText="Region" SortExpression="Region" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT EmployeeID, LastName, FirstName, Region FROM Employees WHERE (City=@City)"
ConnectionString="Server=localhost;Database=Northwind;Trusted_Connection=true">
<SelectParameters>
<asp:ControlParameterControlID="DropDownList1" Name="City" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DetailsViewAutoGenerateRows="False" DataKeyNames="EmployeeID"
DataSourceID="SqlDataSource3"
HeaderText="Employee Details" ID="DetailsView1" runat="server" Width="275px">
<Fields>
<asp:BoundFieldDataField="EmployeeID" HeaderText="ID" ReadOnly="True" />
<asp:BoundFieldDataField="LastName" HeaderText="Last" />
<asp:BoundFieldDataField="FirstName" HeaderText="First" />
<asp:BoundFieldDataField="Region" HeaderText="Region" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ConnectionString="Server=localhost;Database=Northwind;Trusted_Connection=true" ID="SqlDataSource3"
runat="server" SelectCommand="SELECT EmployeeID, LastName, FirstName, Region FROM Employees WHERE (EmployeeID = @EmployeeID)">
<SelectParameters>
<asp:ControlParameterControlID="GridView1" Name="EmployeeID" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</form></body></html>
    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章