How Can I Show Just Date In A BoundColumn (Date Format In SQL Server 2008 Not DateTime) In RadComboBox

11 posts, 0 answers
  1. Majid Darab
    Majid Darab avatar
    110 posts
    Member since:
    Sep 2012

    Posted 27 Jan 2010 Link to this post

    hi my dear friends:

    How Can I Show Just Date In A BoundColumn (Date Format In SQL Server 2008 Not DateTime) In Rad ComboBox?

    we do not have any DataFormatString For A Bound Column here Like In RadGrid....
  2. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 27 Jan 2010 Link to this post

    If you are binding this directly from a SQL database  then you shouldn't have a problem with displaying the date just as it's displayed in the database. Are you attempting to bind this through SQL or are you approaching it in a different matter (list of DateTimes etc.)?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Majid Darab
    Majid Darab avatar
    110 posts
    Member since:
    Sep 2012

    Posted 27 Jan 2010 Link to this post

    hi my dear Schlurk
    i have a date column (not date time) in one of my tables in my database and connet that table to a sql datasource....
    sql data source is connected to rad combobox...
    i set the DATE Type column as the text of my radcombo box ...
    when rad combo box shows this column it adds 12:00 pm automatically to my date...
    how can i remove this and show just date in radcombobox like my sql server table...
    thanks a lot
  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 29 Jan 2010 Link to this post

    Hi Majid Darab,

    There are many options to format date - more about this topic you can find here.
    You can use various format strings to achieve date and time format that you prefer.

    All the best,
    Kalina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Majid Darab
    Majid Darab avatar
    110 posts
    Member since:
    Sep 2012

    Posted 29 Jan 2010 Link to this post

    hello dear admin ...
    i read your link and it was very useful.
    but how can i use string.format in rad combobox databound columns?
    how can i tell rad combo box to use that string format to show just date (not date time) ?
    when u add items in codebehind so you can do this ...
    but what about data bound columns ????????
  7. Majid Darab
    Majid Darab avatar
    110 posts
    Member since:
    Sep 2012

    Posted 31 Jan 2010 Link to this post

    any idea?

  8. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 01 Feb 2010 Link to this post

    Hello Majid Darab,

    As I wrote before - there are various ways to format date, and here are two of them:

    - You can format date in ItemTemplate of the RadComboBox like this:

    <telerik:RadComboBox ID="RadComboBoxProduct" runat="server"
        Height="200px" Width="177px" DropDownWidth="177px"
        AllowCustomText="true" EmptyMessage="Choose a Product"
        MarkFirstMatch="true" HighlightTemplatedItems="true">
        <ItemTemplate>
            <%# DataBinder.Eval(Container.DataItem, "StartDate", "{0:d}")%>
        </ItemTemplate>
    </telerik:RadComboBox>

    protected void Page_Load(object sender, EventArgs e)
    {
        string sqlSelectCommand = "SELECT TOP 1000 [ProductID], [StartDate] FROM [AdventureWorks].[Production].[ProductCostHistory]";
     
        SqlDataAdapter adapter = new SqlDataAdapter(sqlSelectCommand,
            ConfigurationManager.ConnectionStrings["AdventureWorksConnectionString1"].ConnectionString);
        DataTable dataTable = new DataTable();
        adapter.Fill(dataTable);
        RadComboBoxProduct.DataSource = dataTable;
        RadComboBoxProduct.DataBind();
    }

    - If you prefer to format date at code behind you can see this example:
    <telerik:RadComboBox ID="RadComboBoxProduct1" runat="server"
        Height="200px" Width="177px" DropDownWidth="177px"
        AllowCustomText="true" EmptyMessage="Choose a Product"
        MarkFirstMatch="true" HighlightTemplatedItems="true">
        <ItemTemplate>
            <%# DataBinder.Eval(Container, "Text")%>
        </ItemTemplate>
    </telerik:RadComboBox>

    SqlDataAdapter adapter3 = new SqlDataAdapter(sqlSelectCommand,ConfigurationManager.ConnectionStrings["AdventureWorksConnectionString1"].ConnectionString);
    DataTable dataTable3 = new DataTable();
    adapter3.Fill(dataTable3);
     
    foreach (DataRow dataRow in dataTable.Rows)
    {
        RadComboBoxItem item = new RadComboBoxItem();
        item.Value = dataRow["ProductID"].ToString();
       
        DateTime data = (DateTime)dataRow["StartDate"];
        item.Text = data.ToString("dd.mm.yyyy");
     
        RadComboBoxProduct1.Items.Add(item);
        item.DataBind();
    }

    Best wishes,
    Kalina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Majid Darab
    Majid Darab avatar
    110 posts
    Member since:
    Sep 2012

    Posted 01 Feb 2010 Link to this post

    really really appreciate it

    i test your code
    in radcombobox dropdown everything was ok  and i had date not datetime...
    but in radcombobox textbox (after choosing an item) i had datetime??? -> How can i convert this to date?
    best regards
  10. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 03 Feb 2010 Link to this post

    Hi Majid Darab,

    Please take a look at the code below, note that there are two properties DataTextField  and DataTextFormatString.

    At DataTextField we set the name of the item field which we display in the RadComboBox, and at DataTextFormatString we set the formatting string.

    <telerik:RadComboBox ID="RadComboBoxProduct" runat="server"
        Height="200px" Width="177px"
        DropDownWidth="177px" AllowCustomText="true"
        EmptyMessage="Choose a Product"
        MarkFirstMatch="true" HighlightTemplatedItems="true"
        DataTextField="StartDate" DataTextFormatString="{0:d}" >
        <ItemTemplate>
            <%# DataBinder.Eval(Container.DataItem, "StartDate", "{0:d}")%>
        </ItemTemplate>
    </telerik:RadComboBox>


    Greetings,
    Kalina
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  11. Majid Darab
    Majid Darab avatar
    110 posts
    Member since:
    Sep 2012

    Posted 03 Feb 2010 Link to this post

    really really thanks a lot
  12. Ken
    Ken avatar
    10 posts
    Member since:
    Nov 2012

    Posted 11 Feb 2014 in reply to Kalina Link to this post

    I also want to say thank you for posting this line.  Specifically the "{0:d}" part.  I've been looking for this and I've found hundreds (maybe thousands) of posts with a link to here http://msdn.microsoft.com/en-us/library/az4se3k1.aspx which is great but without the line of code below I still don't know how to use it in a sentence.

    But like all the people in those hundreds of messages I needed to see the line below.  Just like that...I'm off and running and will never need assistance on this again!  Thank you!

    <%# DataBinder.Eval(Container.DataItem, "StartDate", "{0:d}")%>

    Ken
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017