Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to present data on datagrid in another pattern

Reply
Thread Tools

How to present data on datagrid in another pattern

 
 
ad
Guest
Posts: n/a
 
      03-27-2005
I have a employee table, with a filed sexID
The field store 1 for male and 2 for female.
I want to display this field in a DataGrid with male or female , not 1 or 2.
How can I do that?


 
Reply With Quote
 
 
 
 
Mike Douglas
Guest
Posts: n/a
 
      03-27-2005
Hi,

You need to capture the ItemDataBound event which is fired for each
row when it is being bound and change the value. Here's the code.
This only works if it is a DataBound Column. If its a Template Column
then you will need to pull the label control out of cell, cast it, and
then set the value.

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Dim sexIDColumn As Integer = 5 ' whatever the column number is
If e.Item.ItemType = ListItemType.EditItem Or e.Item.ItemType
= ListItemType.AlternatingItem Then
' Get sexID
If e.Item.Cells(sexIDColumn).Text = "1" Then
e.Item.Cells(sexIDColumn).Text = "male"
Else
e.Item.Cells(sexIDColumn).Text = "female"
End If
End If
End Sub

I hope this helps.

Mike Douglas

On Sun, 27 Mar 2005 09:01:06 +0800, "ad" <(E-Mail Removed)> wrote:

>I have a employee table, with a filed sexID
>The field store 1 for male and 2 for female.
>I want to display this field in a DataGrid with male or female , not 1 or 2.
>How can I do that?
>


 
Reply With Quote
 
 
 
 
ad
Guest
Posts: n/a
 
      03-27-2005
Thank!
Can we use Template to do that?


"Mike Douglas" <(E-Mail Removed)>
???????:(E-Mail Removed) ...
> Hi,
>
> You need to capture the ItemDataBound event which is fired for each
> row when it is being bound and change the value. Here's the code.
> This only works if it is a DataBound Column. If its a Template Column
> then you will need to pull the label control out of cell, cast it, and
> then set the value.
>
> Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal
> e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
> DataGrid1.ItemDataBound
> Dim sexIDColumn As Integer = 5 ' whatever the column number is
> If e.Item.ItemType = ListItemType.EditItem Or e.Item.ItemType
> = ListItemType.AlternatingItem Then
> ' Get sexID
> If e.Item.Cells(sexIDColumn).Text = "1" Then
> e.Item.Cells(sexIDColumn).Text = "male"
> Else
> e.Item.Cells(sexIDColumn).Text = "female"
> End If
> End If
> End Sub
>
> I hope this helps.
>
> Mike Douglas
>
> On Sun, 27 Mar 2005 09:01:06 +0800, "ad" <(E-Mail Removed)> wrote:
>
> >I have a employee table, with a filed sexID
> >The field store 1 for male and 2 for female.
> >I want to display this field in a DataGrid with male or female , not 1 or

2.
> >How can I do that?
> >

>



 
Reply With Quote
 
Mike Douglas
Guest
Posts: n/a
 
      03-27-2005
Do you mean if you are using a Template Column and want to do it in
code behind or do you want to do it in the markup page?

I think this code should work for the code behind. If you want to do
it in the markup page create a vbfunction using the <script>that takes
in the <%# Databinder... stuff %> and returns the "male" or "female"
based on the 1 or 2.

Dim sexIDColumn As Integer = 5 ' whatever the column number is
If e.Item.ItemType = ListItemType.EditItem Or e.Item.ItemType
= ListItemType.AlternatingItem Then
' Get sexID
Dim sexID As Label
' control(0) is a blank literal control
sexID = CType(e.Item.Cells(sexIDColumn).Controls(1),
Label)
If sexID.Text = "1" Then
sexID.Text = "male"
Else
sexID.Text = "female"
End If
End If
End Sub

I hope that takes care of it. Let me know if it doesn't.

Mike Douglas

On Sun, 27 Mar 2005 09:56:49 +0800, "ad" <(E-Mail Removed)> wrote:

>Thank!
>Can we use Template to do that?
>
>
>"Mike Douglas" <(E-Mail Removed)>
>???????:(E-Mail Removed) m...
>> Hi,
>>
>> You need to capture the ItemDataBound event which is fired for each
>> row when it is being bound and change the value. Here's the code.
>> This only works if it is a DataBound Column. If its a Template Column
>> then you will need to pull the label control out of cell, cast it, and
>> then set the value.
>>
>> Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal
>> e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
>> DataGrid1.ItemDataBound
>> Dim sexIDColumn As Integer = 5 ' whatever the column number is
>> If e.Item.ItemType = ListItemType.EditItem Or e.Item.ItemType
>> = ListItemType.AlternatingItem Then
>> ' Get sexID
>> If e.Item.Cells(sexIDColumn).Text = "1" Then
>> e.Item.Cells(sexIDColumn).Text = "male"
>> Else
>> e.Item.Cells(sexIDColumn).Text = "female"
>> End If
>> End If
>> End Sub
>>
>> I hope this helps.
>>
>> Mike Douglas
>>
>> On Sun, 27 Mar 2005 09:01:06 +0800, "ad" <(E-Mail Removed)> wrote:
>>
>> >I have a employee table, with a filed sexID
>> >The field store 1 for male and 2 for female.
>> >I want to display this field in a DataGrid with male or female , not 1 or

>2.
>> >How can I do that?
>> >

>>

>


 
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
OS present but not present. XPD NZ Computing 4 04-11-2007 11:22 PM
How to present data on ASPxGrid in another pattern ad ASP .Net 2 03-27-2005 07:14 AM
Anomoly using pattern to remove superfluous final \, if present Richard Lionheart Ruby 12 07-10-2004 02:43 PM
Schema: express that "@a present if and only if @b present", where @a, @b are attributes Ralf Wahner XML 5 12-24-2003 11:37 AM
producing XML to present data: design pattern? Gabriel_k XML 0 08-11-2003 11:07 PM



Advertisments