GridView中的几种格式化方法

1,直接写

           <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>

 2,字段格式化

    ﹤asp:GridView ID="grvResult" runat="server" AutoGenerateColumns="False" Width="100%"﹥
    ﹤Columns﹥ 
    ﹤asp:BoundField HeaderText="预定日期" DataField="OperationDate" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="False"﹥ ﹤/asp:BoundField﹥ ﹤asp:BoundField HeaderText="订单总计"    DataField="TotalRate" DataFormatString="{ 0:C}" HtmlEncode="False"﹥ 
    ﹤/asp:BoundField﹥
    ﹤/Columns﹥
    ﹤/asp:GridView﹥

 3,通过占位符

<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>
posted @ 2014-07-16 10:01  namehwh  阅读(818)  评论(0编辑  收藏  举报