频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

ASP.NET2.0:AdventureWorks贸易分析(2)

来源:pcdog 作者:佚名 出处:巧巧读书 2008-02-29 进入讨论组

  3. 产品子类别显示过程
 
  产品子类别页面允许向用户显示所有产品子类别的列表,然后通过所有产品列表中包括的各个子类别进行导航。示例3说明了产品子类别页面的实现。
 
  示例3:产品子类别显示页面
 

 <%@ Page Language="C#" MasterPageFile="~/Common.master" Title="Product Sub Category Display" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:ObjectDataSource ID="subCategorySource"
TypeName="AdventureWorksTraderBiz.ProductSubcategoryBiz"
SelectMethod="GetProductSubCategories" runat="server">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="ProductCategoryID"
Direction="Input" Name="productCategoryID" DefaultValue="1"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:Label runat="server" ID="lblHeading" Font-Size="Medium"
Font-Underline="False" ForeColor="#0000C0">
Click on the SubCategory to go to the Products
</asp:Label><br />
<br />
<asp:GridView HeaderStyle-HorizontalAlign="Center"
HeaderStyle-Font-Bold="True" HeaderStyle-BackColor="blue"
HeaderStyle-ForeColor="White" AutoGenerateColumns="False"
ID="gridSubCategories" runat="server" DataSourceID="subCategorySource">
<Columns>
<asp:BoundField ReadOnly="True" HeaderText="SubcategoryID"
DataField="ProductSubcategoryID" />
<asp:BoundField HeaderText="CategoryID" DataField="ProductCategoryID" />
<asp:HyperLinkField HeaderText="Name" DataTextField="Name"
DataNavigateUrlFields="ProductSubcategoryID"
DataNavigateUrlFormatString='"ProductDisplay.aspx?' ProductSubcategoryID="{0}" />
<asp:BoundField HeaderText='"Row' Guid" DataField="Rowguid" />
<asp:BoundField HeaderText='"Modified' Date" HtmlEncode="false" DataFormatString="{0:MM/dd/yyyy}" DataField="ModifiedDate" />
</Columns>
</asp:GridView>
</asp:Content>


 
  示例3包括名为subCategorySource的ObjectDataSource控件,该控件绑定了ProductSubcategoryBiz类的GetProductSubCategories()方法。正如前文讲解的那样,GetProductSubCategories()方法可接受产品类别ID为参数,同时返回属于该产品类别的所有子类别信息。为了调用这个方法,subCategorySource控件应该将产品类别ID(由产品类别显示页面返回)传递给该方法。在这种情况下,使用QueryStringParameter集合获取产品类别ID.为此,将QueryStringParameter模板的QueryStringField设置为查询字符串字段名称,同时将Name属性设置为GetProductSubcategories()方法参数的名称。这样在前面页面选中的产品类别ID则用于SQL查询的参数。开发人员还可以使用DefaultValue属性设置产品类别ID默认值为1.当首次请求页面时,将使用默认值。

URL:http://www.qqread.com/aspdotnet/n399262.html 更多文章 更多内容请看.NET移动与嵌入式技术.NET开发手册ASP.NET教程专题,或进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章