473,480 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataGrid Column - DataTextFormatString

I'm trying to implement a datagrid with dynamically created columns. The
data is coming out of a very simple XML file, and it's bound through a
dataview.

The datagrid is just a shell definition with no column definitions in the
..aspx file.

The grid is binding fine with all the data being displayed, but my numeric
columns aren't being formatted. I'm using the "dataformattextstring", but
it doesn't seem to be working. Is there anything else I need to do?

Thanks for any help you can give,
Larry

example of my code:

Dim dgc as datagridcolumn

dgc.HeaderText = "Title"
dgc.DataNavigateUrlField = "account"
dgc.DataNavigateUrlFormatString = "detail.aspx={0}"
dgc.DataTextField = "account"
dgc.DataTextFormatString = "{0:n}"

dg.Columns.Add(dgc)



Nov 18 '05 #1
3 4055
Hi,

the string formatting does not work if the underlying type (the type to be
formatted) is string itself as string formatting works from other types to
String. You would need to manage this say in ItemDataBound event, i.e catch
the string value, cast to the correct type and then apply formatting. Might
seem bit overkill, though. So how are you getting the XML? By loading into
DataSet? If yes, you might consider specifying the data type for the
generated DataTable's columns so that you get typed reference to the data
wehn binding (and again formatting to work)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"McNutt Consulting" <la***@mcnutt-consulting.com> wrote in message
news:T9********************@giganews.com...
I'm trying to implement a datagrid with dynamically created columns. The
data is coming out of a very simple XML file, and it's bound through a
dataview.

The datagrid is just a shell definition with no column definitions in the
.aspx file.

The grid is binding fine with all the data being displayed, but my numeric
columns aren't being formatted. I'm using the "dataformattextstring", but
it doesn't seem to be working. Is there anything else I need to do?

Thanks for any help you can give,
Larry

example of my code:

Dim dgc as datagridcolumn

dgc.HeaderText = "Title"
dgc.DataNavigateUrlField = "account"
dgc.DataNavigateUrlFormatString = "detail.aspx={0}"
dgc.DataTextField = "account"
dgc.DataTextFormatString = "{0:n}"

dg.Columns.Add(dgc)


Nov 18 '05 #2
where are you trying to do the formatting? From the contents of your post,
it seems that you want to format items in the autogenerated columns. If
that's the case, what you have used so far applies formatting to the
template columns. Autogenerated columns behave differently because they
aren't added to the column collection so you don't have access to them prior
to databinding. To fix this, add this code to your itemdatabound event
handler

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)

{

double input = e.Item.Cells[3].Text;

e.Item.Cells[3].Text = input.ToString("#,###,.0");

[snip]

roughly
--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b

"McNutt Consulting" <la***@mcnutt-consulting.com> wrote in message
news:T9********************@giganews.com...
I'm trying to implement a datagrid with dynamically created columns. The
data is coming out of a very simple XML file, and it's bound through a
dataview.

The datagrid is just a shell definition with no column definitions in the
.aspx file.

The grid is binding fine with all the data being displayed, but my numeric
columns aren't being formatted. I'm using the "dataformattextstring", but
it doesn't seem to be working. Is there anything else I need to do?

Thanks for any help you can give,
Larry

example of my code:

Dim dgc as datagridcolumn

dgc.HeaderText = "Title"
dgc.DataNavigateUrlField = "account"
dgc.DataNavigateUrlFormatString = "detail.aspx={0}"
dgc.DataTextField = "account"
dgc.DataTextFormatString = "{0:n}"

dg.Columns.Add(dgc)


Nov 18 '05 #3
Thanks,

Your explanation makes sense to me. The XML file doesn't articulate the
type of data (which is numeric). The XML file is generated on the fly from
a COM object and is simply loaded into a dataview via the following
statements:

Dim xtr As XmlTextReader = New XmlTextReader(oXml, XmlNodeType.Document,
Nothing)
ds.ReadXml(xtr, XmlReadMode.Auto)

[oXml is a string variable.]

I will try to set the datatype on the DS or possily use the databind event.
Did want to much overkill like you said. If you could give me a little more
detail about ("consider specifying the data type for the generated
DataTable's columns") I would much appreciate it. Do you mean establish all
the columns of the DS manually?

Thanks for your response.

Larry

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

the string formatting does not work if the underlying type (the type to be
formatted) is string itself as string formatting works from other types to
String. You would need to manage this say in ItemDataBound event, i.e catch the string value, cast to the correct type and then apply formatting. Might seem bit overkill, though. So how are you getting the XML? By loading into
DataSet? If yes, you might consider specifying the data type for the
generated DataTable's columns so that you get typed reference to the data
wehn binding (and again formatting to work)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"McNutt Consulting" <la***@mcnutt-consulting.com> wrote in message
news:T9********************@giganews.com...
I'm trying to implement a datagrid with dynamically created columns. The data is coming out of a very simple XML file, and it's bound through a
dataview.

The datagrid is just a shell definition with no column definitions in the .aspx file.

The grid is binding fine with all the data being displayed, but my numeric columns aren't being formatted. I'm using the "dataformattextstring", but it doesn't seem to be working. Is there anything else I need to do?

Thanks for any help you can give,
Larry

example of my code:

Dim dgc as datagridcolumn

dgc.HeaderText = "Title"
dgc.DataNavigateUrlField = "account"
dgc.DataNavigateUrlFormatString = "detail.aspx={0}"
dgc.DataTextField = "account"
dgc.DataTextFormatString = "{0:n}"

dg.Columns.Add(dgc)



Nov 18 '05 #4

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

Similar topics

1
1342
by: Tim Smith | last post by:
In my .cs code I populate set the DataSource appropriately and I can get my DataGrid to appear, though sorting throws an error 'dgDataGrid1__ctl1__ctl0' of type 'DataGridLinkButton' must be placed...
3
6960
by: KatB | last post by:
Hi, I'm building a datagrid with a column to show + or - signs for expanding/collapsing child rows, etc. It works okay except since I'm using a LinkButton column there is an underline below the...
3
1225
by: Terry Olsen | last post by:
I have a datagrid filled with shipping records. I would like to make the field that contains the tracking numbers to be links where the user can click and automatically track that particular...
5
2750
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
0
994
by: Annie | last post by:
hello guys, can i use this propety of the hyperlink column to customised my output? Let is say i have a bound column of text from database as hyperlink which could be longer however i want to...
1
1289
by: arun.hallan | last post by:
My datagrid displays large numbers pulled from the database in standard form. EG - 1,172,060 is displayed as -1.17206e+006 How do i get it to display numbers in full?
7
1660
by: coosa | last post by:
In an asp.net 2.0 GridView web control, is it possible to display one column as a hyperlink which displays a name, such as item_name from a db table, but capures the item_id when clicked? If yes,...
3
4343
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
2
1267
by: =?Utf-8?B?RXNlbWk=?= | last post by:
I have a datatable that contains a number of web addresses as type nvarchar (eg 'www.msdn.com'). I want to use these as hyperlinks in a datagrid column. Whats the best way to do this? How can I...
0
7048
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
6911
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...
1
6743
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
6966
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...
0
4488
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...
0
2999
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...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
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...

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.