Datafield in Datagrid

Discussion in 'ASP .Net Datagrid Control' started by Alison, Jul 31, 2005.

  1. Alison

    Alison Guest

    I need to change the contents of the datafield to make it look a bit
    more userfriendly.

    What I have at the moment is as follows:
    <asp:BoundColumn DataField="retired" HeaderText="Retire
    Status"></asp:BoundColumn>

    Where the "retired" is extacted from a database table and has a bit
    datatype; so either 0 or 1. When the grid is displayed, I have written
    some code to change the default 'false' or 'true' values to show
    'active' or 'retired'. That works fine.

    The code I use is:
    Sub Item_Bound(ByVal sender As Object, ByVal e As
    DataGridItemEventArgs)

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

    ' Retrieve the text of the RetiredColumn from the
    DataGridItem
    ' and convert the value .
    If e.Item.Cells(3).Text = "False" Then

    ' Format the value as Active and redisplay it in the
    DataGrid.
    e.Item.Cells(3).Text = "Active"
    Else ' retirement status is 'retired'
    e.Item.Cells(3).Text = "Retired"

    End If
    End If
    End Sub

    However, when I click on the Edit button to update the contents of that
    row in the datagrid, it again displays 'true' or 'false' in the
    editable textbox. This is not what I want. I want it to show either
    'retired' or 'active'. How can I do this? A drop-down box would be best
    for this, but I'm trying to keep things simple at this point until I"m
    a bit more experienced with asp.net.

    TIA
     
    Alison, Jul 31, 2005
    #1
    1. Advertising

  2. Alison

    Elton Wang Guest

    Hi Alison,

    Actually, the simple way is to convert the retired value in your SQL query.

    Instead of using

    SELECT retired, . FROM table_name

    You can use

    Select (CASE WHEN retired = 1 THEN 'Retired' ELSE 'Active' END) AS
    retired, ... FROM table_name

    HTH

    "Alison" <> wrote in message
    news:...
    > I need to change the contents of the datafield to make it look a bit
    > more userfriendly.
    >
    > What I have at the moment is as follows:
    > <asp:BoundColumn DataField="retired" HeaderText="Retire
    > Status"></asp:BoundColumn>
    >
    > Where the "retired" is extacted from a database table and has a bit
    > datatype; so either 0 or 1. When the grid is displayed, I have written
    > some code to change the default 'false' or 'true' values to show
    > 'active' or 'retired'. That works fine.
    >
    > The code I use is:
    > Sub Item_Bound(ByVal sender As Object, ByVal e As
    > DataGridItemEventArgs)
    >
    > If e.Item.ItemType = ListItemType.Item Or _
    > e.Item.ItemType = ListItemType.AlternatingItem Then
    >
    > ' Retrieve the text of the RetiredColumn from the
    > DataGridItem
    > ' and convert the value .
    > If e.Item.Cells(3).Text = "False" Then
    >
    > ' Format the value as Active and redisplay it in the
    > DataGrid.
    > e.Item.Cells(3).Text = "Active"
    > Else ' retirement status is 'retired'
    > e.Item.Cells(3).Text = "Retired"
    >
    > End If
    > End If
    > End Sub
    >
    > However, when I click on the Edit button to update the contents of that
    > row in the datagrid, it again displays 'true' or 'false' in the
    > editable textbox. This is not what I want. I want it to show either
    > 'retired' or 'active'. How can I do this? A drop-down box would be best
    > for this, but I'm trying to keep things simple at this point until I"m
    > a bit more experienced with asp.net.
    >
    > TIA
    >
     
    Elton Wang, Jul 31, 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. Adil Bohoudi
    Replies:
    1
    Views:
    469
    Eric Wise
    Aug 6, 2003
  2. richard

    get DataField value in UpdateCommand

    richard, Dec 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    430
    richard
    Dec 2, 2003
  3. Replies:
    1
    Views:
    2,318
  4. ahmad_n80
    Replies:
    0
    Views:
    488
    ahmad_n80
    Jul 21, 2007
  5. et

    Get the datafield of a column in datagrid

    et, Dec 28, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    165
    Eliyahu Goldin
    Jan 2, 2005
Loading...

Share This Page