This is a migrated thread and some comments may be shown as answers.

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

10 Answers 423 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Majid Darab
Top achievements
Rank 1
Majid Darab asked on 27 Jan 2010, 02:15 PM
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....

10 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 27 Jan 2010, 03:51 PM
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.)?
0
Majid Darab
Top achievements
Rank 1
answered on 27 Jan 2010, 04:00 PM
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
0
Kalina
Telerik team
answered on 29 Jan 2010, 04:52 PM
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.
0
Majid Darab
Top achievements
Rank 1
answered on 30 Jan 2010, 04:56 AM
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 ????????
0
Majid Darab
Top achievements
Rank 1
answered on 31 Jan 2010, 11:41 AM
any idea?

0
Kalina
Telerik team
answered on 01 Feb 2010, 02:07 PM
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.
0
Majid Darab
Top achievements
Rank 1
answered on 01 Feb 2010, 03:32 PM
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
0
Kalina
Telerik team
answered on 03 Feb 2010, 09:52 AM
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.
0
Majid Darab
Top achievements
Rank 1
answered on 03 Feb 2010, 04:29 PM
really really thanks a lot
0
Ken
Top achievements
Rank 1
answered on 11 Feb 2014, 01:43 PM
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
Tags
ComboBox
Asked by
Majid Darab
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Majid Darab
Top achievements
Rank 1
Kalina
Telerik team
Ken
Top achievements
Rank 1
Share this question
or