Need to Format a zipcode into xxxxx-xxxx.

Discussion in 'ASP .Net Datagrid Control' started by Jeff Thur, Feb 18, 2005.

  1. Jeff Thur

    Jeff Thur Guest

    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.
    ..
     
    Jeff Thur, Feb 18, 2005
    #1
    1. Advertising

  2. Jeff Thur

    RJ Guest

    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)




    "Jeff Thur" <> wrote in message
    news:021701c51553$6b75d380$...
    > 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.
    > .
    >
    >
     
    RJ, Feb 18, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DaveF

    ZIPCODE DB ACCESS TO SQL

    DaveF, Sep 29, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    442
    Scott M.
    Sep 30, 2004
  2. sjl
    Replies:
    3
    Views:
    417
    MasterGaurav
    Apr 28, 2005
  3. Jeff Thur
    Replies:
    1
    Views:
    151
    Alvin Bruney [MVP]
    Feb 17, 2005
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    199
    Iñaki Baz Castillo
    Feb 8, 2011
  5. Replies:
    3
    Views:
    280
    Andy Dingley
    Sep 27, 2006
Loading...

Share This Page