Home All Groups Group Topic Archive Search About

Need to Format a zipcode into xxxxx-xxxx.

Author
18 Feb 2005 12:47 AM
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.
..

Author
18 Feb 2005 4:14 AM
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)




Show quoteHide quote
"Jeff Thur" <j***@emscirc.com> wrote in message
news:021701c51553$6b75d380$a501280a@phx.gbl...
> 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.
> .
>
>