删除时添加提示:
http://topic.csdn.net/u/20110125/11/d7e035e6-98e2-4772-a09a-19162123b209.html
http://apps.hi.baidu.com/share/detail/15195109
http://www.cnblogs.com/pyt5208/archive/2007/11/19/964365.html
Eval格式化
http://apps.hi.baidu.com/share/detail/51649429
GridView数据常用格式化类型
数字 {0:N2} 12.36
数字 {0:N0} 13
数字 {0:D} 12345 12345
数字 {0:D8} 12345 00012345
数字 {0:F} 12345.6789 12345.68
数字 {0:F0} 12345.6789 12346
数字 {0:G} 12345.6789 12345.6789
数字 {0:G7} 123456789 1.234568E8
货币 {0:c2} $12.36
货币 {0:c4} $12.3656
货币 "¥{0:N2}" ¥12.36
科学计数法 {0:E3} 1.23E+001
百分数 {0:P} 12.25%
日期 {0:D} 2006年11月25日
日期 {0:d} 2006-11-25
日期 {0:f} 2006年11月25日 10:30
日期 {0:F} 2006年11月25日 10:30:00
日期 {0:s} 2006-11-26 10:30:00
时间 {0:T} 10:30:00
时间 {0:t} 10:30
HyperLinkField
特别说明HyperLinkField,是因为实现了DataGrid的HyperLinkColumnd所不支持的,多参数格式化链接。通常我们附加在url后面的QueryString不会只有一个,asp.net 1。x 中只有使用绑定列,然后手动写代码:
<asp:DataGrid id="DataGrid1" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink runat="server" Text="View Photo" NavigateUrl='<%# String.Format("photo.aspx?empid={0}&path={1}", Eval("EmployeeID"), Eval("PhotoPath")) %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
现在使用HyperLinkField,看下,省去很多苦力活:)
复制 保存
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="EmployeeID,City" DataNavigateUrlFormatString="photo.aspx?empid={0}&path={1}"
HeaderText="PhotoPath" Text="View Photo" />
</Columns>
</asp:GridView>
注意:
1、.aspx中 DataNavigateUrlFields 中多个 Field 使用 , (逗号)分隔
2、裕绑定的Url 实际值,不能为完整的绝对的路径(如:http://www.cnblogs.com/Jinglecat/archive/2007/05/20/753284.html),而应该提供相对路径(如:Jinglecat/archive/2007/05/20/753284.html),否则该URL整个不会被输出,应该是HyperLinkField内部做了HTML监测,但它又不提供开关属性如BoundField
的HtmlEncode给开发人员,应该算一个bug吧!
空值(Null)处理
如果字段的值为空,则可以通过设置 NullDisplayText 属性显示自定义标题。
通过将 ConvertEmptyStringToNull 属性设置为 true,BoundField 对象,也可以将空字符串 ("") 字段值自动转换为空值。