Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datafield in Datagrid

Reply
Thread Tools

Datafield in Datagrid

 
 
Alison
Guest
Posts: n/a
 
      07-31-2005
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

 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      07-31-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the datafield of check boxes that checked in datagrid(with java script)? ahmad_n80 ASP .Net 0 07-21-2007 09:38 AM
Access to DataField of DataGrid paolo.ponzano@gmail.com ASP .Net 1 05-18-2006 08:42 AM
Get the datafield of a column in datagrid et ASP .Net Datagrid Control 3 01-02-2005 08:41 AM
get DataField value in UpdateCommand richard ASP .Net 0 12-02-2003 07:35 AM
show just the date in a datagrid column when the datafield is an datetime field Adil Bohoudi ASP .Net 1 08-06-2003 04:07 PM



Advertisments