473,796 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView DataFormatStrin g at RunTime

bsm
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.

May 4 '07 #1
3 6718
yourDate.ToStri ng("MM-dd-yyyy");

Ray at work

"bsm" <se************ *@saksoft.co.in wrote in message
news:11******** **************@ e65g2000hsc.goo glegroups.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.
May 4 '07 #2
bsm
On May 4, 7:19 pm, "Ray Costanzo" <my first name at lane 34 dot
commercialwrote :
yourDate.ToStri ng("MM-dd-yyyy");

Ray at work

"bsm" <senthilmurug.. .@saksoft.co.in wrote in message

news:11******** **************@ e65g2000hsc.goo glegroups.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?

May 5 '07 #3
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?
May 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1621
by: Gerhard Pretorius | last post by:
Since installing the VS.NET August CTP the DataFormatString of the BoundField in the Gridview does not work. Runtime v2.0.50727. <asp:BoundField DataField="Event_Date" DataFormatString="{0:yyyy/MM/dd}" It still shows the date as "2005/05/03 12:45 AM" It worked in beta 2, don't knwo about July CTP, but August CTP is a problem v2.0.50727
1
2006
by: Gerhard Pretorius | last post by:
I am reposting this..hoping someone (from Microsoft) can confirm this at least as a problem: Since installing the VS.NET August CTP the DataFormatString of the BoundField in the Gridview and Details view does not work. Runtime v2.0.50727. <asp:BoundField DataField="Event_Date" DataFormatString="{0:#0.0}" It still shows the value as 23.04
2
4636
by: | last post by:
Hi all, I have a gridview control with a bound field as outlined below. The problem is that the formatting is not happening. The data gets rendered as 12999.0000. It is being stored in a decimal data type. Any ideas? <asp:boundfield headertext="Amount" datafield="amount" dataformatstring="{0:C}"/> TIA!
1
6640
by: Hardy Wang | last post by:
Hi, I have a GridView control in my web form (ASP.NET 2.0) <asp:GridView ID="gvReport" runat="server" AllowSorting="True" AutoGenerateColumns="False" Width="100%"> <HeaderStyle CssClass="ItemCaption" /> <RowStyle CssClass="Line" /> <AlternatingRowStyle CssClass="AltLine" /> <Columns> <asp:BoundField DataField="ItemName" HeaderText="Item
2
16361
by: Rob Roberts | last post by:
I have a GridView that is bound to a collection of DateTimes (i.e. - Collection<DateTime>). I have a BoundField in the GridView, and its DataField is set to the DateTime's Date property, and the DataFormatString is set to "{0:d}" in order to display the date in short date format (without the time). But the DataFormatString doesn't seem to have any effect. The DateTime gets displayed with the time. I have another GridView that is bound...
4
8180
by: Eamonn | last post by:
Hi I am running Microsoft Visual Studio 2005 Team Edition Version 8.0.50727.42. I am adding columns to a GridView at runtime. When I add a BoundField that will contain DateTime data I want to format the date so I use: BoundField.DataFormatString = <myDateFormat> However it just displays the date formatting string in the GridView and not the formatted date. I tried setting the HtmlEncode value for the
0
1769
by: jobo | last post by:
Hey there, I'm having a problem getting sorting to work. Here's what the GridView looks like: "server" ID="updt1" Mode="Conditional">
5
6523
by: Tim Mackey | last post by:
hi, with a derived DataGrid control, i can override the CreateColumnSet method and scan into the DataGridColumns and set the DataFormatString, e.g. leave out the time part of a DateTime value. this works great for a DataGrid control. however i'm upgrading this control to inherit from GridView. there seems to be a limitation of the gridview "Method not supported" when you try and set a DataFormatString on an AutoGeneratedField.
3
1938
by: Nathan Sokalski | last post by:
I have a GridView control with three columns, all BoundField columns. They all have a HeaderText and DataField property set, and the third one has a DataFormatString property as well. When I run my code, the GridView displays two sets of columns. The first set looks exactly as I would expect. The second set, which should not be there anyway, uses the DataField as the header and does not apply the DataFormatString for the third column. What...
0
9527
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10453
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.