Click here to Skip to main content
15,566,305 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I am working on a web application and I am applying RowUpdating event and updating the result in a datetable.
In design view
<pre lang="xml">asp:TemplateField HeaderText="Date of Birth" SortExpression="D_O_B">
            <EditItemTemplate>
                <asp:TextBox ID="txtgrddob" runat="server"
                    Text='<%# Eval("D_O_B","{0:dd/MMM/yyyy}") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblgrddob" runat="server" Text='<%# Bind("D_O_B","{0:dd/MMM/yyyy}") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>




In code
DataRow dr = ds.Tables[0].Rows.Find(grdReplicate.DataKeys[e.RowIndex].Values[0].ToString());
dr["D_O_B"] = txtdob.Text;


When I store this dataset inside the datatable,I am not getting the dateformat in
dd/MMM/YYYY format.

I Have used ToString and string.format method
Posted
Updated 19-Apr-11 5:15am
v2
Comments
BobJanova 19-Apr-11 10:15am    
edit: added ASP.net tag

1 solution

The DateTime Format is only used for displaying the date in human readable format. The representation of a DateTime object in the code is always the same. Store the DateTime in the data table as a DateTime, and your problem is solved because your Label is formatting the date for you.
 
Share this answer
 
Comments
Pratik Bhesaniya 19-Apr-11 10:05am    
Nicely done
BobJanova 19-Apr-11 10:16am    
Yes, data should always be kept in its original form in data, not stored as a string representation, where that is possible.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900