Datafield in Datagrid

A

Alison

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
 
E

Elton Wang

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
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top