GridView中的字符串格式化
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" AllowSorting="True" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting" OnRowUpdating="GridView1_RowUpdating" PageSize="6"
OnRowEditing="GridView1_RowEditing" OnRowDataBound="GridView1_RowDataBound1" Height="158px">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="UserID" HeaderText="用户ID" ReadOnly="True" />
<asp:BoundField DataField="User_Nm" HeaderText="用户姓名" />
<asp:BoundField DataField="User_Sex" HeaderText="性别" />
<asp:BoundField DataField="User_Address" HeaderText="家庭住址" />
<asp:TemplateField HeaderText="出生日期">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("User_Birthday","{0:M-dd-yyyy}") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("User_Birthday","{0:M-dd-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="选择" ShowSelectButton="True" />
<asp:CommandField HeaderText="编辑" ShowEditButton="True" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
</Columns>
<RowStyle ForeColor="#008066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
页面后台代码同以前的代码。只是把前台的出生日期作为模板列来操作。
根据CSDN的清清月儿的写法,还可以<asp:BoundField DataField="User_Birthday" HeaderText ="出生日期" HtmlEncode="false" />
只需要增加HtmlEncode设置为False。