473,725 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Runtime DataGrid formating

I have a datagrid where I specified {0:###,###,###} at design time. However
sometimes I am putting percentages in the grid instead of money and I want
to change the formating to {##%}. I've looked over the docs on such things
as the dataformatstrin g porperty of the boundColumn but still can't figure
out how to do it in code.

Thank,
T
Nov 19 '05 #1
3 1422
This is what I did, it is not very good, but will allow you to do
processing.

Example:
On the aspx/ascx page, I would like to retrieve the the date for the the
particular record
so i call a function coded in the aspx.cs/ascx.cs which is GetDate, I will
pass in the record in the datagrid

<%# GetDate(Contain er.DataItem) %>

On the aspx.cs/ascx.cs, I will process the dataItem, which return the short
date for my datagrid

public string GetDate(Object obj)
{
string topicDate = ((DataRowView)o bj)["topicDate"].ToString();
return Convert.ToDateT ime(topicDate). ToShortDateStri ng();
}

-----------------------------------------------------------------

If you would like a better and much more professional way, this article
might help

http://openmymind.net/databinding/index.html

Joey

"Tina" <ti**********@r emovespamexcite .com> wrote in message
news:u9******** ******@TK2MSFTN GP10.phx.gbl...
I have a datagrid where I specified {0:###,###,###} at design time.
However sometimes I am putting percentages in the grid instead of money and
I want to change the formating to {##%}. I've looked over the docs on such
things as the dataformatstrin g porperty of the boundColumn but still can't
figure out how to do it in code.

Thank,
T

Nov 19 '05 #2
Ouch, pretty ugly but thank you for the help. The article is also very
good.
T

"Joseph Lee" <jo*********@ho tmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
This is what I did, it is not very good, but will allow you to do
processing.

Example:
On the aspx/ascx page, I would like to retrieve the the date for the the
particular record
so i call a function coded in the aspx.cs/ascx.cs which is GetDate, I will
pass in the record in the datagrid

<%# GetDate(Contain er.DataItem) %>

On the aspx.cs/ascx.cs, I will process the dataItem, which return the
short date for my datagrid

public string GetDate(Object obj)
{
string topicDate = ((DataRowView)o bj)["topicDate"].ToString();
return Convert.ToDateT ime(topicDate). ToShortDateStri ng();
}

-----------------------------------------------------------------

If you would like a better and much more professional way, this article
might help

http://openmymind.net/databinding/index.html

Joey

"Tina" <ti**********@r emovespamexcite .com> wrote in message
news:u9******** ******@TK2MSFTN GP10.phx.gbl...
I have a datagrid where I specified {0:###,###,###} at design time.
However sometimes I am putting percentages in the grid instead of money
and I want to change the formating to {##%}. I've looked over the docs on
such things as the dataformatstrin g porperty of the boundColumn but still
can't figure out how to do it in code.

Thank,
T


Nov 19 '05 #3
Joseph,
I found a way to do it without having to put code manually into the .aspx
file.
In the ItemDataBound event just do:
myString = e.item.Cells(x) .text 'the number without editing mask
myInteger = val(myString)
e.item.cells(x) .text = myInteger.tostr ing("##%")

Works great!
T
"Joseph Lee" <jo*********@ho tmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
This is what I did, it is not very good, but will allow you to do
processing.

Example:
On the aspx/ascx page, I would like to retrieve the the date for the the
particular record
so i call a function coded in the aspx.cs/ascx.cs which is GetDate, I will
pass in the record in the datagrid

<%# GetDate(Contain er.DataItem) %>

On the aspx.cs/ascx.cs, I will process the dataItem, which return the
short date for my datagrid

public string GetDate(Object obj)
{
string topicDate = ((DataRowView)o bj)["topicDate"].ToString();
return Convert.ToDateT ime(topicDate). ToShortDateStri ng();
}

-----------------------------------------------------------------

If you would like a better and much more professional way, this article
might help

http://openmymind.net/databinding/index.html

Joey

"Tina" <ti**********@r emovespamexcite .com> wrote in message
news:u9******** ******@TK2MSFTN GP10.phx.gbl...
I have a datagrid where I specified {0:###,###,###} at design time.
However sometimes I am putting percentages in the grid instead of money
and I want to change the formating to {##%}. I've looked over the docs on
such things as the dataformatstrin g porperty of the boundColumn but still
can't figure out how to do it in code.

Thank,
T


Nov 19 '05 #4

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

Similar topics

3
2466
by: Rameshika | last post by:
Hi All How can I select a particular row in a datagrid.Where when the user double clicks the data in that row should appear in the corresponding text boxes in runtime And how can the user insert,delete and edit fields in a datagrid at runtime Please be kind enough to help me Thanks Rameshika
0
1099
by: Diogo Alves - Software Developer | last post by:
Hi there, I have a big problem here, I am binding a database table to a dataset and then populate a datagrid the problem is that I have a column that is named TOTALMINUTES and type real.... On the datagrid I want to show that result on the format hh:mm converting those minutes to hours and minutes.... I only can see 2 solution: First - Use Column.Expression : Since I have to do formating and lot of stuff I could not get a expression to...
1
1320
by: DJ Dev | last post by:
Hi, I am stuck at a problem for 3 days now. I create runtime datagrids depending on the user selections and they may vary from 2-10 depending on user selection at runtime. The datagrids are created in a loop at runtime and I assign IDs as DG0, DG1...and so on in the loop itself. The datagrid has a template column created at runtime with checkboxes. They may vary from 3-7 varying from datagrid to datagrid. Once that is done and i have been...
1
1380
by: Tayo | last post by:
What is best way of having a consistent datagrid format on multiple pages? Any ideas welcome Tayo
2
5862
by: Steve Pierce | last post by:
I am having some issues with a runtime dropdownlist in a datagrid. The issue is that I cannot get ViewState to fill the selected index of a runtime dropdown properly on postback. I do not want to use template columns as they seem to be a little difficult to create at runtime. Any assistance would be very greatly appreciated. private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if...
1
1010
by: Thomas Beyerlein | last post by:
Hello, I am loading a dataGrid and formatting it with datagridtablestyle, but when it loads different info it does not clear the old. With out the formatting the code works. I have tried clearing the datagrid tablestyles. Any other ideas would be helpful. Thanks Tom
4
315
by: BrianDH | last post by:
Hi I have a datagrid that I populate with a web service dataset. All fields are sent to text. However, one field will not show its value. You can click on a row and see that info in the grid's dataset, but the column is empty. What I have found is if the text that is passed into this field is EX: "This is a test"
1
5757
by: Tor Inge Schulstad | last post by:
Hi. I need to change the fontsize and vertical alignment of the text in a datagrid. It's a Windows forms application, and I'm using tablestyles to format my datagrid. I do not need to format cells or rows individually. The settings are going to be used on the entire daragrid. Can anyone guide me in the right direction to do this? __
0
1890
by: musawer | last post by:
Can Someone give a good link for C# Winform DataGrid Text Style Formating (Font,Color,Size etc)... Quick reply will be highly appreciated... Thanks...
0
8888
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
8752
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
9401
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...
1
9176
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
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
8097
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
6702
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...
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
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.