Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
160
Problem with WebDropDown date display
posted

I have an issue with webdropdowns. I'm using WebDropDowns in a WebDatagrid via dropdownprovider. The dropdown contains a list of dates. The date format shown in the grid cell is correct, and the data format down in the list part of dropdown list is correct. But the value shown in the dropdown control itself is incorrect. The incorrect date format only shows up when I click on any cell the dropdown column. I uploaded an image of this issue, and hope it can explain better. The image is in this link: http://imgur.com/c5C4Y2E Please help me get the date format fixed.

More detail on my grid set up if it helps with the issue:

I'm using the dropdown in a BoundDataField inside a WebDataGrid. The BoundDataField has these properties set: Key="DropDown" DataFormatString="{0:ddd M/dd}" DataType="System.DateTime"

And the editor control inside the dropdownprovider has these properties set: EditorControl ID="DropDownControl" DisplayMode="DropDownList" ClientEvents-SelectionChanged="Some_Event"

The datasource for the Dropdown control is a dataset with 2 columns, one column has the type DateTime, and dropdown's ValueField is set to this column. The other column in the dataset is type string, it holds the date converted to {0:ddd M/dd} format, and the dropdown's TextField is set to this column.

Thanks,

Dan Ding

Parents
  • 4315
    Offline posted

    Hi, Dan.

    I hope I will be able to help you with my answer.

    Unfortunately the Text Field of the WebDropDown cannot be formatted and it always takes the item that is bound to, on the server-side. I can ensure that cause I've checked it in the drop down code and it always uses the text that is rendered from the server (You can open the Developer tools, search for the whole date (Thu Jan 14 2016...) and see how it is rendered in the client-side data source).

    So one of the ways to do that is that your data source entity is formatted date. As far it is coming from a data base, you can use the ItemBound event, and inside to format the date that you want, for each individual date:

    protected void WebDropDown1_ItemBound(object sender, Infragistics.Web.UI.ListControls.DropDownItemBoundEventArgs e)
        {
            ((Infragistics.Web.UI.ListControls.DropDownItem)e.Value).Text = ((Infragistics.Web.UI.ListControls.DropDownItem)e.Value).Text.Replace(" 12:00:00 AM", "");
        }

    The format depends on your needs. In your case you can take the Text value transform it to date and then take the day, month and day from the weak and concatenate them. Here is an article about that. Note that when the date is formatted on the server, then maybe you will not need additional formatting in the grid and in the list items.

    Here a similar problem was discussed.

    I will wait for your feedback.

    Best Regards,

    Nikolay Alipiev

    Software Developer

Reply Children