您的位置:知识库 » .NET技术

ASP.NET 2.0数据教程之四:使用ObjectDataSource展现数据

作者: №.零零伍  来源: 博客园  发布时间: 2008-10-07 12:16  阅读: 7294 次  推荐: 0   原文链接   [收藏]  

系列文章导航:

ASP.NET 2.0数据教程之一:创建一个数据访问层

ASP.NET 2.0数据教程之二:创建一个业务逻辑层

ASP.NET 2.0数据教程之三:母板页和站点导航

ASP.NET 2.0数据教程之四:使用ObjectDataSource展现数据

ASP.NET 2.0数据教程之五:声明参数

ASP.NET 2.0数据教程之六:编程设置ObjectDataSource的参数值

ASP.NET 2.0数据教程之七:使用DropDownList过滤的主/从报表

ASP.NET 2.0数据教程之八:使用两个DropDownList过滤的主/从报表

ASP.NET 2.0数据教程之九:跨页面的主/从报表

ASP.NET 2.0数据教程之十:使用 GridView 和DetailView实现的主/从报表

ASP.NET 2.0数据教程之十一:基于数据的自定义格式化

ASP.NET 2.0数据教程之十二:在GridView控件中使用TemplateField


 

花一些时间修改GridView控件的绑定列,移除ProductID, SupplierID, CategoryID, QuantityPerUnit, UnitsInStock, UnitsOnOrder, ReorderLevel这几列。操作很简单,从左下方的列表中选中这些列然后点击删除按钮(红色交叉)就可以移除它们。然后,重新排列一下,选中CategoryName SupplierName两个绑定列并点击向上箭头按钮,使它们排放在UnitPrice列之前。分别设置ProductsCategorySupplier Price这几个剩下的绑定列的HeaderText属性。然后,格式化Price列为货币设置该绑定列的HtmlEncode属性为False并且设置DataFormatString属性为{0:c} 。最后,通过ItemStyle/HorizontalAlign属性设置绑定列Price的水平靠右对齐以及CheckBoxDiscontinued水平居中显示。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"    DataKeyNames="ProductID" DataSourceID="ObjectDataSource1" EnableViewState="False">

    <Columns>

        <asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />

        <asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />

        <asp:BoundField DataField="SupplierName" HeaderText="Supplier" ReadOnly="True" SortExpression="SupplierName" />

        <asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="Price"

            HtmlEncode="False" SortExpression="UnitPrice">

            <ItemStyle HorizontalAlign="Right" />

        </asp:BoundField>

        <asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued">

            <ItemStyle HorizontalAlign="Center" />

        </asp:CheckBoxField>

    </Columns>

</asp:GridView>


8: GridView控件的绑定列定制完成

 

0
0

.NET技术热门文章

    .NET技术最新文章

      最新新闻

        热门新闻