473,385 Members | 1,838 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,385 software developers and data experts.

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 dataformatstring porperty of the boundColumn but still can't figure
out how to do it in code.

Thank,
T
Nov 19 '05 #1
3 1406
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(Container.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)obj)["topicDate"].ToString();
return Convert.ToDateTime(topicDate).ToShortDateString();
}

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

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

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

Joey

"Tina" <ti**********@removespamexcite.com> wrote in message
news:u9**************@TK2MSFTNGP10.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 dataformatstring 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*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.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(Container.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)obj)["topicDate"].ToString();
return Convert.ToDateTime(topicDate).ToShortDateString();
}

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

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

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

Joey

"Tina" <ti**********@removespamexcite.com> wrote in message
news:u9**************@TK2MSFTNGP10.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 dataformatstring 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.tostring("##%")

Works great!
T
"Joseph Lee" <jo*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.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(Container.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)obj)["topicDate"].ToString();
return Convert.ToDateTime(topicDate).ToShortDateString();
}

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

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

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

Joey

"Tina" <ti**********@removespamexcite.com> wrote in message
news:u9**************@TK2MSFTNGP10.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 dataformatstring 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
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...
0
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...
1
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...
1
by: Tayo | last post by:
What is best way of having a consistent datagrid format on multiple pages? Any ideas welcome Tayo
2
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...
1
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...
4
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...
1
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...
0
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.