473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to set BoundColumn DataFormatString in CodeBehind?

In ASP.Net v1.1 and C# suppose one has:
protected System.Web.UI.WebControls.DataGrid MyGrid;

In Page_Load I want to do the equivalent of:

MyGrid.Columns[MyDateColumnIndex].DataFormatString="{0:d}";

or

MyGrid.Columns[MyDateColumnIndex].DataFormatString="{0:g}";

depending on some user style flag that determines how much date/time details the user
wants to see.
But DataFormatString is not a field for the Columns[] array.

Is there a way to do this?
Dec 12 '05 #1
1 5615
Hi Randall,

You needed to cast the column to its type, e.g.

((BoundColumn)MyGrid.Columns[MyDateColumnIndex]).DataFormatString = "{0:d}";
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Randall Parker" wrote:
In ASP.Net v1.1 and C# suppose one has:
protected System.Web.UI.WebControls.DataGrid MyGrid;

In Page_Load I want to do the equivalent of:

MyGrid.Columns[MyDateColumnIndex].DataFormatString="{0:d}";

or

MyGrid.Columns[MyDateColumnIndex].DataFormatString="{0:g}";

depending on some user style flag that determines how much date/time details the user
wants to see.
But DataFormatString is not a field for the Columns[] array.

Is there a way to do this?

Dec 12 '05 #2

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

Similar topics

1
by: Lars Pedersen | last post by:
Hi. I'm having a datagrid which i build dynamically in codebehind, adding each column to the grid. One of the Boundcolumns contains an Image, and that's ok. I just want the formatstring to...
1
by: frank | last post by:
I am using the DataFormatString property on BoundColumn objects in a DataGrid, but they don't seem to work for some reason. I copied them straight from another DataGrid where they work fine, but...
7
by: Volodymyr Lozovoy | last post by:
Hi All, who suggest why subj do not affect on displayed result for date?
1
by: Kenny | last post by:
Hi, <asp:BoundColumn DataField="LongDescription" DataFormatString=... Is it possible to use DataFormatString to truncate the Description display in Datagrid? Or any suggestion?? It is a...
9
by: Roy | last post by:
Hey all, Ok, I have a boundcolumn in a datagrid which displays a smalldatetime field from a table. Behold: <asp:BoundColumn DataField="final_appvl_dt" SortExpression="final_appvl_dt"...
1
by: news.wanadoo.nl | last post by:
Hi, Is there a sollution for a DataFormatString as currency that shows always the euro sign: ? <asp:BoundColumn DataField="UnitCost" HeaderText="Prijs"...
0
by: cntams | last post by:
Hi all, I have a Web Form and using BoundColumn to bind data to the datagrid. I have 2 fields that needs to be formatted. The first one is a DateTime field and the second one is the currency...
4
by: ThunderMusic | last post by:
Hi, I have a datagrid. In my datagrid I have a DataBoundColumn with the property DataFormatString set to "{0:F2}" so it should format the content of the cell to a floating number with 2 digits. It...
1
by: jeffg | last post by:
Hi, I have a DataGrid in a ASP.NET application (.NET 1.1) where one of the BoundColumns in the datagrid is displaying a Date and Time stamp. I would like to display just a short date...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.