Parse asp:boudfield in a gridview
I have the following gridview: I need to parse the first 8 elements of the datetime and view these only in the gridview. How can i do that?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" BackColor="White"
BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
CellPadding="1" DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
GridLines="Horizontal" CellSpacing="4" Height="20px"
Width="842px" ShowFooter="True">
<FooterStyle BackColor="White" ForeColor="#333333" />
<RowStyle ForeColor="#333333" BackColor="White" />
<Columns>
<asp:ButtonField CommandName="Select" Visible="false" />
<asp:BoundField DataField="ID" HeaderText="ID" HeaderStyle-HorizontalAlign="Left" InsertVisible="False" ReadOnly="True" />
<asp:BoundField DataField="title" HeaderStyle-HorizontalAlign="Left" HeaderText="Title"/>
<asp:BoundField DataField="location" HeaderStyle-HorizontalAlign="Left" HeaderText="Location"/>
<asp:BoundField DataField="datetime" HeaderStyle-HorizontalAlign="Left" HeaderText="Datetime"/>
</Columns>
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
</asp:GridView>开发者_开发问答;
Try this:
<asp:BoundField DataFormatString="{0:MM/dd/yy}" DataField="datetime" HeaderStyle-HorizontalAlign="Left" HeaderText="Datetime" />
精彩评论