当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 使用 ASP+ 列表绑定控件(下)

ASP.NET
asp.net GridView控件中模板列CheckBox全选、反选、取消
asp.net GridView 删除时弹出确认对话框(包括内容提示)
asp.net DropDownList 三级联动下拉菜单实现代码
asp DataTable添加列和行的三种方法
Asp.net 页面调用javascript变量的值
asp.net 长文章通过设定的行数分页
asp.net 定时间点执行任务的简易解决办法
asp.net 页面延时五秒,跳转到另外的页面
asp.net 动态输出透明gif图片
asp.net DataList与Repeater用法区别
asp.net Javascript获取CheckBoxList的value
asp.net程序在调式和发布之间图片路径问题的解决方法
asp.net下生成英文字符数字验证码的代码
asp.net 页面版文本框智能提示JSCode (升级版)
ASP.NET URL伪静态重写实现方法
ASP.NET 2.0 中Forms安全认证
asp.net 动态添加多个用户控件
asp.net Repeater显示父子表数据,无闪烁
asp.net 无法获取的内部内容,因为该内容不是文本 的解决方法
asp.net GridView排序简单实现

ASP.NET 中的 使用 ASP+ 列表绑定控件(下)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 41 ::
收藏到网摘: n/a

DataGrid3

  DataGrid3通过添加可视格式化和内容格式化构建于DataGrid2之上。

摘自 DataGrid3.aspx:

〈%@ Page language="C#" src="DataGrid.cs" inherits="Samples.Data
GridPage"%〉
...

〈asp:DataGrid runat=server id="titlesGrid"
   AutoGenerateColumns="false"
   Width="80%"
   BackColor="White"
   BorderWidth="1px" BorderStyle="Solid" CellPadding="2" Cell
   Spacing="0"
   BorderColor="Tan"
   Font-Name="宋体" Font-Size="8pt"〉
 〈property name="Columns"〉
  〈asp:BoundColumn headerText="Title" DataField="title"/〉
  〈asp:BoundColumn headerText="Author" DataField="au_name"/〉
  〈asp:BoundColumn headerText="Date Published" DataField=
  "pubdate"
     DataFormatString="{0:MMM yyyy}"/〉
  〈asp:BoundColumn headerText="Price" DataField="price"
   DataFormatString="{0:c}"〉
   〈property name="ItemStyle"〉
    〈asp:TableItemStyle HorizontalAlign="Right"/〉
   〈/property〉
  〈/asp:BoundColumn〉
 〈/property〉

 〈property name="headerStyle"〉
  〈asp:TableItemStyle BackColor="DarkRed" ForeColor="White"
   Font-Bold="true"/〉
 〈/property〉
 〈property name="ItemStyle"〉
  〈asp:TableItemStyle ForeColor="DarkSlateBlue"/〉
 〈/property〉
 〈property name="AlternatingItemStyle"〉
  〈asp:TableItemStyle BackColor="Beige"/〉
 〈/property〉
〈/asp:DataGrid〉

  此.aspx文件显示了与前面相同的DataGrid控件声明,并设置了各种
样式属性。这将导致视觉上更具吸引力的表示。仍就不需要对代码进行任
何更改,使用与以前示例相同的有代码支持的文件。

  因为它是从 WebControl 得到的,所以 DataGrid 控件继承了诸如
Width、BackColor、BorderStyle 和 Font.Name 之类的样式属性。此外,
DataGrid提供诸如CellPadding这样的属性,这些属性是特定于表的。这
些属性允许从总体上定制控件。

  声明还显示了设置的若干项目样式,如headerStyle和Alternating
ItemStyle。这些样式控制着它们相应项目的外观。请注意此示例中出现
的样式合并。备选项目与一般项目的前景色相同,因为它们的样式是
AlternatingItemStyle和ItemStyle的组合。最后,此示例还通过右对齐
价格列中的文本说明了为特定列设置样式。

  DataGrid还允许您格式化其单元格中的文本内容。这是通过设置Bound
Column的DataFormatString属性值完成的。该列使用其格式说明格式化使
用 String.Format的单元格内容。此属性可随格式化类型(如日期或货币)
一起预置或附加任意内容。此外,由于格式化考虑了当前页的CultureInfo
和请求,所以它也支持全局化。如果未指定格式,则使用该值的ToString
方法。

DataGrid4

  DataGrid4 说明如何通过处理 SelectedIndexChanged 事件来利用
DataGrid 中的选择。

截自 DataGrid4.aspx:

〈%@ Page language="C#" src="DataGrid4.cs" inherits="Samples.
DataGrid4Page"%〉
...

〈asp:DataGrid runat=server id="titlesGrid"
   AutoGenerateColumns="false"
   Width="80%"
   BackColor="White"
   BorderWidth="1px" BorderStyle="Solid" CellPadding="2"
   CellSpacing="0"
   BorderColor="Tan"
   Font-Name="宋体" Font-Size="8pt"
   DataKeyField="title_id"
   OnSelectedIndexChanged="OnSelectedIndexChangedTitlesGrid"〉
 〈property name="Columns"〉
  〈asp:ButtonColumn Text="Select" Command="Select"/〉
  〈asp:BoundColumn headerText="Title" DataField="title"/〉
  〈asp:BoundColumn headerText="Author" DataField="au_name"/〉
  〈asp:BoundColumn headerText="Date Published" DataField=
  "pubdate"
     DataFormatString="{0:MMM yyyy}"/〉
  〈asp:BoundColumn headerText="Price" DataField="price"
   DataFormatString="{0:c}"〉
   〈property name="ItemStyle"〉
    〈asp:TableItemStyle HorizontalAlign="Right"/〉
   〈/property〉
  〈/asp:BoundColumn〉
 〈/property〉

 〈property name="headerStyle"〉
  〈asp:TableItemStyle BackColor="DarkRed" ForeColor="White"
   Font-Bold="true"/〉
 〈/property〉
 〈property name="ItemStyle"〉
  〈asp:TableItemStyle ForeC