【问题标题】:How to remove time format from dropdownlist ASP.NET如何从下拉列表 ASP.NET 中删除时间格式
【发布时间】:2014-05-30 00:49:52
【问题描述】:

我有一个下拉列表,其中填充了数据库作为日期值。在数据库中,类型数据是'日期'而不是时间,但下拉列表加载了时间格式

 Dim da = New SqlDataAdapter("SELECT DISTINCT tahun_lulus_kuliah from alumni", conn)
    Dim ds = New DataSet
    ds.Clear()
    da.Fill(ds, "alumni")
    DropDownList1.DataSource = ds.Tables("alumni")
    DropDownList1.DataValueField = ("tahun_lulus_kuliah")
    DropDownList1.DataBind()

这是下拉列表的截图,是否可以将格式下拉列表更改为“yyyy/mm/dd”而没有时间格式?

非常感谢 希望你的回答

【问题讨论】:

    标签: c# asp.net combobox crystal-reports-2010


    【解决方案1】:

    您需要将DropDownList.DataTextFormatString 设置为"{0:yyyy/mm/dd}"

    <asp:DropDownList id="DropDownList1"
        ...
        DataTextFormatString="{0:yyyy/mm/dd}"/>
    

    【讨论】:

    • 我会这样,但输出结果什么都没有,下拉列表仍然给出相同的格式,没有变化,谢谢
    【解决方案2】:

    类似的东西。如果你想在后端做。不是VB男孩所以我还没有确认。

    Binding dateBinding = new Binding("tahun_lulus_kuliah", ds.Tables("alumni"), "")
    
    dateBinding.FormattingEnabled = True
    dateBinding.FormatString = "yyyy/mm/dd"
    DropDownList.DataBindings.Add(dateBinding)
    

    【讨论】:

    • 您好托尼先生,非常感谢您的先生,但是您能给我c#代码吗,我没问题,
    • 我也修复了您问题上的标签,只是需要更改的 vb dim。还没有证明。更多信息在这里msdn.microsoft.com/en-us/library/aa480734.aspx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多