How can you show the date in a gridview as a date only instead of a datetime?

前端 未结 10 1473
粉色の甜心
粉色の甜心 2021-02-04 01:22

I am pulling in date values from a sql server database using a gridview and and the date gets converted from

12/12/2009 to 12/12/2009 12:

相关标签:
10条回答
  • 2021-02-04 01:47

    You can set the date format in the bound column like this

    <itemtemplate>
    <asp id="Label1" runat="server" Label.Text='<%# Bind("YourDateField", "{0:M-dd-yyyy}") %>'>;
    </asp>
    </itemtemplate>
    
    0 讨论(0)
  • 2021-02-04 01:48

    use this in query where you are getting date field

    CONVERT(VARCHAR,date column name,103) as date
    

    ex:select column1,column2,CONVERT(VARCHAR,date column name,103) as date from tablename

    0 讨论(0)
  • 2021-02-04 01:52

    when you select the field from the database you can convert it to a string in the select as:

    convert(varchar, myDate, 101)
    
    0 讨论(0)
  • 2021-02-04 01:58
    for (int j = 0; j < gv_bill_dmd_process_create.Rows.Count; j++)
                    {
                        GridViewRow row_fees = (GridViewRow)gv_bill_dmd_process_create.Rows[j];
                        TextBox gv_chk_bill_dept = row_fees.FindControl("txt_gv_DmdProsDuedate") as TextBox;
                        AjaxControlToolkit.CalendarExtender gv_chk_bill_dept1 = row_fees.FindControl("txt_gv_DmdProsDuedate_CalendarExtender") as AjaxControlToolkit.CalendarExtender;
                        gv_chk_bill_dept1.StartDate = fromdate;
                        gv_chk_bill_dept1.EndDate = todate;
                    }
    
    0 讨论(0)
提交回复
热议问题