Setting Date format in dropdown list

后端 未结 5 1100
孤城傲影
孤城傲影 2021-01-19 11:50

I am retrieving date values from dataset(_dsst) and populating them in dropdown list(drpStartYear).

Since I am storing date as datetime datatype, I am

相关标签:
5条回答
  • 2021-01-19 12:10

    Below code worked for me, I was using DataValueField, which didnot allow me to use DataTextFormatString, So When I changed it to DataTextField, I got intended results :)

     drpStartYear.DataSource = _dstt.Tables["tbSettings"].DefaultView;    
     drpStartYear.DataTextField = "StartDate";  
    
     drpStartYear.DataTextFormatString = "{0:d}";   
     drpStartYear.DataBind();  
    
    0 讨论(0)
  • 2021-01-19 12:12

    You have to set DataTextField as well -

      drpStartYear.DataValueField = "StartDate";
    
      drpStartYear.DataTextField = "StartDate";
      drpStartYear.DataTextFormatString = "{0:dd-MM-yyyy}";
      drpStartYear.DataBind();
    
    0 讨论(0)
  • 2021-01-19 12:24

    Did you try:

    drpStartYear.DataTextFormatString = "0:dd/MM/yyyy HH:mm:ss";  
    
    0 讨论(0)
  • 2021-01-19 12:25
    drpStartYear.DataTextFormatString = "{0:dd-MM-yyyy}";
    drpStartYear.DataTextField = "StartDate";
    

    or you can set this in your mark-up as follows:

    <asp:DropDownList
    id="drpStartYear"
    runat="server"
    DataTextField = "StartDate"
    DataTextFormatString="{0:dd-MM-yyyy}"/>
    
    0 讨论(0)
  • 2021-01-19 12:35
    drpStartYear.DataTextFormatString = "{0:dd-MM-yyyy}";
    

    EDIT: Add this:

    drpStartYear.DataTextField = "StartDate";
    
    0 讨论(0)
提交回复
热议问题