Set the dataformat string to "MM-dd-yyyy"
Example:
ASPX:
<asp:DataGrid ID="dg" runat="server" AutoGenerateCol umns="false">
<Columns>
<asp:BoundColum n DataField="dt" DataFormatStrin g="{0:MM-dd-yyyy}"
HeaderText="For matted Version" />
<asp:BoundColum n DataField="dt" HeaderText="Unf ormatted Version" />
</Columns>
</asp:DataGrid>
CS: (binds some bogus data)
protected void Page_Load(objec t sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add( "dt", Type.GetType("S ystem.DateTime" ));
for (int q = 1; q < 11; q++)
{
DataRow r = dt.NewRow();
r["dt"] = System.DateTime .Now.AddDays(q) ;
dt.Rows.Add(r);
}
dg.DataSource = dt;
dg.DataBind();
}
Ray at work
"bsm" <se************ *@saksoft.co.in wrote in message
news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
On May 4, 7:19 pm, "Ray Costanzo" <my first name at lane 34 dot
commercialwrote :
>yourDate.ToStr ing("MM-dd-yyyy");
Ray at work
"bsm" <senthilmurug.. .@saksoft.co.in wrote in message
news:11******* *************** @e65g2000hsc.go oglegroups.com. ..
>I have created GridView and assign Datasource at RunTime. I need to
format one Column which will have the following data.
Start_date Want to Format as
Start_date
--------------
------------------------------------------
10-Mar-2005 10:50:00 10-03-2005
Discard Time and change the Date Format.
Please anyone tell me how to achieve this.- Hide quoted text -
- Show quoted text -
Let me explain my problem more clearly.
1. I drag and drop GridView in Design time.
2. In run time I assigned the Datasource and Bind it.
3. The gridview contains 4 columns, one of them is DataTime.
4. Which will display the data like "10-Mar-2005 10:50:00".
5. But our user don't like to see the Time in the Gridview report.
6. I need to eliminate the Time during the RunTime (or if u have any
idea, plz suggest).
7. What I did was, in the prerender event I tried to set the
"DATAFORMATSTRI NG" property of the column.
8. But it throws error.
Hope I explained my issue step by step.
Plz guide me what to do?