如何在Gridview中插入日期和时间

时间:2013-01-30 11:52:18

标签: datetime gridview time record

再次,新问题。请引导下面的图片。

enter image description here

这是输出(见下图): enter image description here

以下是results.aspx

中Gridview的代码
<asp:GridView runat="server" id="GridView1" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" DataKeyNames="ID" BorderStyle="Ridge" BackColor="White" BorderColor="Black" BorderWidth="3px" CellPadding="3" Width="1000px" AllowPaging="True" PageSize="2">
            <RowStyle BackColor="White" ForeColor="#003399" HorizontalAlign="Center" VerticalAlign="Middle" />
            <Columns>
                <asp:boundfield DataField="Time In" HeaderText="Time In" SortExpression="Time In">
                    <ItemStyle Width="100px" />
                </asp:boundfield>
                <asp:boundfield DataField="Username" HeaderText="Bar Code No." SortExpression="Username">
                </asp:boundfield>
                <asp:boundfield DataField="FirstName" HeaderText="First Name" SortExpression="FirstName">
                </asp:boundfield>
                <asp:boundfield DataField="LastName" HeaderText="Last Name" SortExpression="LastName">
                </asp:boundfield>
                <asp:boundfield DataField="MiddleName" HeaderText="Middle Name" SortExpression="MiddleName">
                </asp:boundfield>
                <asp:boundfield DataField="ContactNumber" HeaderText="Contact No." SortExpression="ContactNumber">
                </asp:boundfield>
                <asp:boundfield DataField="PlateNumber" HeaderText="Plate No." SortExpression="PlateNumber">
                </asp:boundfield>
                <asp:boundfield DataField="Color" HeaderText="Color" SortExpression="Color">
                </asp:boundfield>
                <asp:boundfield DataField="Brand" HeaderText="Brand" SortExpression="Brand">
                </asp:boundfield>
                <asp:boundfield DataField="LiscensedNumber" HeaderText="Liscensed No." SortExpression="LiscensedNumber">
                </asp:boundfield>
                <asp:templatefield>
                    <HeaderTemplate>
                        Image
                    </HeaderTemplate>
                    <ItemTemplate>
                        <img src="data:image/jpg;base64,<%# Eval("Image") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("Image")) : string.Empty %>" alt="image" height="85" width="85" />
                    </ItemTemplate>
                </asp:templatefield>
            </Columns>
            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
            <PagerStyle HorizontalAlign="Center" BackColor="#999999" ForeColor="#003399" />
            <EmptyDataTemplate>
                No data found!
            </EmptyDataTemplate>
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#A0A0A0" Font-Bold="True" ForeColor="#003399" HorizontalAlign="Center" />
            <AlternatingRowStyle BackColor="#DCDCDC" />
        </asp:GridView>

请帮忙。我不知道关于“日期和时间”事情的代码。

3 个答案:

答案 0 :(得分:1)

尝试删除数据字段中的空间,如Rahul R.  它在标题文本中无关紧要,但在数据域中却无关紧要。

答案 1 :(得分:1)

<asp:boundfield datafield="Your_Date_Column" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" />

还要确保数据域名称中没有空格

答案 2 :(得分:0)

很抱歉在这里问我,我解决了。

我转换了templatefield中的列,然后我添加了这段代码

Text='<%# DateTime.Now.ToString("dddd<br /> MMMM dd,  yyyy<br /> hh:mm tt") %> 

:)感谢大家。