DateTime field in DetailsView- problem to convert dd/MM/YYYY date format

Hi guys,

In my DetailsView I have a TextBox control which is inside a TemplateField tag.

The textbox field holds a DateTime value: 


asp:TextBox ID="T_ValidFrom" runat="server" Text='<%# Bind("ValidFrom") %>' Width="70px"></asp:TextBox>

ValideFrom is a public property in my DAL class which my ObjectDataSource is bounded.

Now on DetailsView1.InsertItem(false); I get an error:

Cannot convert value of parameter 'ValidFrom' from 'System.String' to 'System.DateTime'

In my config file I have


globalization culture="en-IE" uiCulture="en-IE" />

and I have inspected



and it is dd/MM/YYYY, but still I get this error. I even set my IE language to English(Ireland) and also set the iis to en-IE as default culture and uiCulture, but still I get this error.

Do I really have to do something manually in


void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{    ....    }

If so how do I have to do it ???

 Please help me with this and I really appreciate your help in advance.


Mehdi Entezary
Please click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
4/26/2007 12:36:52 AM 93655 articles. 6 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 15


   The error shows ..

       Cannot convert value of parameter 'ValidFrom' from 'System.String' to 'System.DateTime'

    Validfrom is not in proper format to get bind with the textbox ... 

    Use this ..

             Text='<%# Bind("ValidFrom.ToString();") // while binding ..

     Hope this may resolve ur problem ..


Mark the post as Answered, if it helps you to fix the problem that you faced.
4/26/2007 5:08:23 AM


Tnx, but I don't have any problem converting DateTime to String. It is String to DateTime that gives me an error.

Thanks anyway

Mehdi Entezary
Please click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
4/26/2007 2:05:26 PM

Hi, Mehdi6002,

The key to solve your question is how to convert string to date.

So we suggest you to do it as follows:

Make sure that the string is a date.

This is a regular expression use to get the right date as follows:


The follows is the domo code.



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="I20070502-StringToDate.aspx.cs" Inherits="_200705_I20070502_StringToDate" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">


<html xmlns="" >

<head runat="server">

    <title>String to Date </title>



    <form id="form1" runat="server">


        <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>

        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtDate"

            ErrorMessage="Please input a right date!" ValidationExpression="^(?=\d)(?:(?!(?:1582(?:\.|-|\/)10(?:\.|-|\/)(?:0?[5-9]|1[0-4]))|(?:1752(?:\.|-|\/)0?9(?:\.|-|\/)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\.|-|\/)(?:29|30))))(\d{4})([-\/.])(0?\d|1[012])\2((?!00)[012]?\d|3[01])(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$"></asp:RegularExpressionValidator>

        <asp:Label ID="lblDate" runat="server" Text=""></asp:Label>

        <asp:Button ID="btnDate" runat="server" Text="SToD" OnClick="btnDate_Click" />







using System;

using System.Web.UI;


public partial class _200705_I20070502_StringToDate : Page


    protected void btnDate_Click(object sender, EventArgs e)


        DateTime dt;

        dt = Convert.ToDateTime(txtDate.Text);

        lblDate.Text = dt.ToString();




Hope it helps.

Hong Gang

Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
5/2/2007 7:29:09 AM

Similar Artilces:

Convert Date Format from mm/dd/yyyy to dd/mm/yyyy
Hi,In my Web application I need to show the date in dd/mm/yyyy format to the user. In my application i am showing the date in various forms e.g. In GridView, In dataGrid, In combo, In textBox will it be possible? ThanksPriyank Kansal  dear,try this, String.Format("{0:yyyy-MM-dd HH:mm:ss}", Now)it will return string like "2007-05-01 12:30:01" set format as per your need.  regards,Niraj sikotara.<!-- Search before you scramble. --!> actually pretty, I am using hundreds of pages in my web application. Now it is very difficult to change the format of ea...

How To Convert dd/mm/yyyy date into mm/dd/yyyy format
Hi My Application recieves date in dd/mm/yyyy format.But I want to convert into dd/mm/yyyy format.If is there any format for that please help me.Debabrata Pattanaik DateTime datenow = DateTime.Now;DateTime convertdate = Convert.ToDateTime(datenow.ToString("mm/dd/yyyy"));Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET now.toString("mm/dd/yyyy")  Hi ,Another way is :-   now.tostring("d");Go to page and change culture property of the page to en-us.Not b...

US date format dd/mm/yyyy gets converted to mm/dd/yyyy
Dear All,I got an sql query that I pass to sql server as a string. I pass a date as a string in the query and compare it to a date in a table.The trouble is somewhere in the process I get ‘01/04/2006’ turned into ‘04/01/2006’ I do understand mm/dd/yyyy is the US date format. The problem is I pass in dd/mm/yyyy and I compare it to dd/mm/yyyy, however it is dd/mm/yyyy gets compared to mm/dd/yyyy for some reason.I tried the 3 variations below, but none works ok, suggesting that the conversion takes place somewhere #in between’. Can someone tell me how to solve this?<code>Dim myDat...

How to convert the date from UK format dd/mm/yyyy to mm/dd/yyyy before sending it to database
I am having a problem with the dates. my application will be used in USA and also in UK. if the date format is like mm/dd/yyyy then i don't have no problem passing it to stored proc to update or insert, but if i pass the date in UK format dd/mm/yyyy i am getting the following error: (String not recognized as date and time) I am getting the following:  txtNeedDate.PostedDate = "31/01/2007"  i want to use a condition, if the date format is in UK then change it to "01/31/2007" before i pass it to database via storted proc. Please does any one know how i can convert the above dat...

date format being changed from mm/dd/yyyy to mm/dd/yyyy hr:mm am
Hello All,i am importing a excel sheet into a sql database. in the excel sheet i have column whose date format is mm/dd/yyyy (07/16/2008). but when ever i import the sheet into the database, its automatically getting changed to 07/16/2008 12:00 am. any idea how i can retain the excel format. any help would be highly appreciated.Thanks  That is the way in SQL Server's datetime data type before we have SQL Server 2008 available. You can format the datetime to remove the time part in your query or format it from client side. Let us know if you need more help.Limno Hello Sir,can you...

Date Format (YYYY/MM/DD) From (MM/DD/YYYY)
I am very new to (started this week)  I have the following line FormatDateTime(dsEdit.FieldValue("BDateStart", Container),2) which is currently displaying the date as MM/DD/YYYY when I need YYYY/MM/DD to suit my database (MySQL)  How can I go about formatting the date to suit my needs?  Thankyou With FormatDateTimeyou have a limited range of formatting options see FormatDateTime(dsEdit.FieldValue("BDateStart", Container),2)to dsEdit.FieldValue("BDateStart", Container).ToString("yyyy/MM/dd") &...

Formatting the Date from dd/mm/yyyy to mm/dd/yyyy
Hi,  I have a textbox in which the date is coming from a javascript calendar in dd/m/yyyy format but i want to change that into mm/dd/yyyy. I am trying to do like this DateTime dtProjectStartDate=Convert.ToDateTime(uxdate.Text);Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); dtProjectStartDate = Convert.ToDateTime(dtProjectStartDate); but it is giving me the error "string was not recognised as a valid datetime. " and i have tried this also but getting the same error. Please help me.DateTime.ParseExact(uxdate.Text...

converting a string field in MM/dd/yyyy format to a date value
hi,   I have a string variable that holds a date in the format MM/dd/yyyy ( eg 10/27/2004 ).  My question - how can I set a Date variable to be this value ?  My cast aDate = CDate(stringval) does not work  eg  Dim aDate as Date  Dim aString as string = "10/27/2004"  aDate = CDate (aString)   --- this cast fails causing an invalid cast error  I can't find a code snippet anywhere. Is it me or is date handling always a nightmare? Apologies in advance for being a dumbo - but at least I am a keen amateur. Kind regards Cha...

Daterange Picker Calendar control Without clicking Start Date and End Date Separately ( dd/mm/yyyy-dd/mm/yyyy format
Hello all,  Plz Suggest me the Daterange Picker Calendar control . so that i can select a range of date (after clicking on button javascipt calendar will be executed) and date will appear in the format dd/mm/yyyy-dd/mm/yyyy in listbox (like without cliking for Start Date and End Date Separately)  Swati Jain   Check this: NC... Some of the third party Calendar controls allow multiple selections. If they support the ability to just click on the start and then end dates to form a range, or can limit the u...

date problems (trying to make a datetime object in format DD/MM/YYYY)
hallo all please help me im trying to make a dateTime object like so:IFormatProvider format = new System.Globalization.CultureInfo("he-IL", true);  Start = DateTime.ParseExact("22/12/2007", "dd/MM/yyyy", format);  ok so i have a computer with regional settings of united states. and i cant make the date time object be DD/MM/YYYY  how do i get arround the regional settings? please please help i even want to make it global for the all project so every time i make a new dateTime object it will be automaticly be in the format of DD/MM/YYYY rega...

How to convert textbox value date from dd/MM/yyyy to MM/dd/yyyy
I have the date in textbox in this format(dd/MM/yyyy), how can i convert textbox1.text date to MM/dd/yyyy. Thank you very much for the information.    TextBox1.Text.ToString( "MM/dd/yyyy" ); Hi, you need to set specific cultrue to parse string to dateTime, and then output desired time format. However I have one simple way to swith day and month.    TextBox1.Text = "08/30/1999";   DateTime temp;    temp = Convert.ToDateTime(TextBox1.Text);   TextBox1.Text = temp.ToString("dd/MM/yyyy"); // or "MM/dd/yyyy" &n...

How to change the format of Date from dd/MM/yyyy -> yyyy/MM/dd
The Code is-protected void btnSave_Click(object sender, EventArgs e) {DataSet ds = new DataSet();SqlDataAdapter adp = new SqlDataAdapter("select max(Int_MemberShipNo) as mem_no from M_CA", con); adp.Fill(ds);if (ds.Tables[0].Rows[0][0].ToString() == "") { mem_no = 1; } else {mem_no = Convert.ToInt16(ds.Tables[0].Rows[0][0]) + 1;Session["mem_no"]=mem_no.ToString(); } DateTime dt_dob = Convert.ToDateTime(txtDOB.Text); DateTime dt_dom = Convert.ToDateTime(txtDOM.Text);if (RadioButtonList1.SelectedItem.Text == "Home") {i = "H"; ...

How to convert datetime in MM/dd/yyyy HH:mm format
Hi,   Very trivial query but I am facing problem for the past five hours I am passing two dates in string format Now I want to retrieve details from sql server from the given dates. The dates will be displayed in dd/MM/yyyy format. But it should be converted to MM/dd/yyyy HH:mm format I tried out the belowstring fromdate = base.Request.Params["FROMDATE"].ToString(); string todate = base.Request.Params["TODATE"].ToString();SqlCommand cmd = new SqlCommand("select gps_datetime,ignition,gps_connected from gpsdata_history where registrationno='" + reg...

date format dd/mm/yyyy in aspx pages but mm/dd/yyyy in access db
I'm working with 2.0 and having the problem that my date/time objects are stored in american format (mm/dd/yyyy) in my access database, but on my page they are in european format (dd/mm/yyyy).How do i get the dates in my database to be in european format.The code follows, the problem is that when i select a date in my calender obj and press the button1, the date is forwarded to the SqlDataSource InsertCommand. (in debug mode i can see that the date that is passed to the SqlDataSource is still in the correct format).In my database i can see that the date has gone from 01/10/2005 to 10...

Web resources about - DateTime field in DetailsView- problem to convert dd/MM/YYYY date format -

Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Beta
In this article, Scott discusses the recently released beta version of Visual Studio 2008 and .NET Framework 3.5 Service Pack 1. He starts with ...

Latest Updates
Latest Updates - Free source code and tutorials for Software developers and Architects.; Updated: 15 Feb 2013 - Upcoming stories is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

<asp:DetailsView ID="grd_empDetails" runat="server" DataSourceID="empDataSource -
Pastebin launched a little side project called , check it out ;-) Don't like ads?

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Latest Updates
Latest Updates - Free source code and tutorials for Software developers and Architects.; Updated: 15 Feb 2013

Resources last updated: 1/7/2016 4:16:00 PM