473,848 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to set BoundColumn DataFormatStrin g in CodeBehind?

In ASP.Net v1.1 and C# suppose one has:
protected System.Web.UI.W ebControls.Data Grid MyGrid;

In Page_Load I want to do the equivalent of:

MyGrid.Columns[MyDateColumnInd ex].DataFormatStri ng="{0:d}";

or

MyGrid.Columns[MyDateColumnInd ex].DataFormatStri ng="{0:g}";

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

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

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

((BoundColumn)M yGrid.Columns[MyDateColumnInd ex]).DataFormatStr ing = "{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.W ebControls.Data Grid MyGrid;

In Page_Load I want to do the equivalent of:

MyGrid.Columns[MyDateColumnInd ex].DataFormatStri ng="{0:d}";

or

MyGrid.Columns[MyDateColumnInd ex].DataFormatStri ng="{0:g}";

depending on some user style flag that determines how much date/time details the user
wants to see.
But DataFormatStrin g 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
1525
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 act as a link, pointing to another page and should contain the ID from a datasource, like this: col = new BoundColumn();
1
2612
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 for some reason they have no effect in the following grid. The two that don't work are DataFormatString="{0:dd-MM-yyyy}" and DataFormatString="{0:C}". The code is below. Anyone got any ideas what the problem is?
7
7801
by: Volodymyr Lozovoy | last post by:
Hi All, who suggest why subj do not affect on displayed result for date?
1
424
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 problem when the Description too long and affect the UI of the page. Thanks,
9
2835
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" DataFormatString="{0:MMM-dd-yyyy}" ReadOnly="True" HeaderText="Final Apprvl Date" ItemStyle-Wrap="false"></asp:BoundColumn>
1
7008
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" DataFormatString="{0:c}"></asp:BoundColumn> <%# DataBinder.Eval(Container.DataItem, "UnitCost", "? {0}") %>
0
1089
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 field. The following is part of my code, the following shows a new boundColumn is being created, and the DataFormatString is being specified. Now, I need to format the currency in a multilanguage manner. Can someone tell me how to do so in both...
4
2353
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 does not work, at the moment it always puts 4 digits (which is the same as before I put the format). What could be the cause? Here is the code for the column... it displays the good data, only not in the good format:
1
3883
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 ("7/5/2005") instead of the full date and time. I am having difficulty understanding the DataFormatString property on the BoundColumn class. I see in the documentation how to change the format for numbers, but don't see how to change the format for dates....
0
9893
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9738
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
10348
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9500
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
7894
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
7069
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();...
1
4544
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
2
4137
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3175
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.