Need to Format a zipcode into xxxxx-xxxx.

J

Jeff Thur

I guess that you can't do this with the property window
of datagrid control. Probably need an itemdatabound event.

How can I program an itemdatabound control to get a column
(Zipcode) to look as such xxxxx-xxxx. It currently is in
this format, xxxxxxxxx.
Thanks for any help.
..
 
R

RJ

Jeff,
It happens that the string formatting is the only part that does work for
me. My problem is changing the cell background color, as in my previous
post. This FormatCells method works for me if it is called by the
DataGrid1_ItemDataBound event handler. The format specifier may be a little
off, but the code certainly executes before the grid displays.

' The ItemDataBound event is handled for each row in datasource......
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

' FormatCells does get called for each row.....
FormatCells(sender, e)
End Sub


Protected Sub FormatCells(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

e.Item.Cells(5).Text = String.Format("ddddd-dddd", zip)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top