Sunday, March 11, 2012

Yes/No field showing up as Yes/No in a datagrid.

you can use template column for that one column if you dont want to change all your code and write a helper function. google for "datagrid + helper function". theres an article on aspalliance.com that I can remember has some sample code too.

hth
The best of doing is in your Sql query .Use CASE stament in your query and change the field value to YES if it's true .
Or if you want to do it from Code see following example(NOT TESTED)


Private Sub DgResult_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DgResult.ItemCommand
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
if (e.Item.Cells(3).Text="True" Then
e.Item.Cells(3).Text = "YES"
Else
e.Item.Cells(3).Text = "NO"
End if
End Select

End Sub


Arvind Malik
I figured it out, thanks for the hint.

Sub dgOutput_ItemDataBound(sender As Object, e As DataGridItemEventArgs)
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.SelectedItem
if (e.Item.Cells(16).Text="True") Then
e.Item.Cells(16).Text = "Yes"
Else
e.Item.Cells(16).Text = "No"
End if
End Select
End Sub

No comments:

Post a Comment