The ASP.NET grid is a composite control so you can iterate within the existing controls and change the style control by control.
Another approach it to format each cell on databinding using a column template that can be applied to a column using the ItemTemplate property.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
I have a DataGrid Control (VB.NET, ASP 1.1) that reads from Access Database.
One of it's columns called "Status" and each cell gets a string value: "opened" or "closed".
How to make all "opened" cells display bold?
Try this sample snippet below
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If (e.Item.ItemType = ListItemType.Item) OrElse (e.Item.ItemType = ListItemType.AlternatingItem) Then
If e.Item.Cells(0).Text = "opened" Then
e.Item.Cells(0).Font.Bold = True 'just changed the index of cells based on your requirements
'or this below
e.Item.Cells(0).Attributes.Add("style", "font-weight:bold")
Else
'Do something here
End If
End If
End Sub
vit0
Member
48 Points
85 Posts
How to format cells in DataGrid?
Aug 20, 2008 05:19 PM|LINK
I have a DataGrid Control (VB.NET, ASP 1.1) that reads from Access Database.
One of it's columns called "Status" and each cell gets a string value: "opened" or "closed".
How to make all "opened" cells display bold?
bass4g0d
Member
354 Points
73 Posts
Re: How to format cells in DataGrid?
Aug 20, 2008 07:13 PM|LINK
The ASP.NET grid is a composite control so you can iterate within the existing controls and change the style control by control.
Another approach it to format each cell on databinding using a column template that can be applied to a column using the ItemTemplate property.
vit0
Member
48 Points
85 Posts
Re: How to format cells in DataGrid?
Aug 20, 2008 07:32 PM|LINK
Theoretically you right, but I need some example
vit0
Member
48 Points
85 Posts
Re: How to format cells in DataGrid?
Aug 21, 2008 08:31 AM|LINK
Help
kyuti
Contributor
2027 Points
549 Posts
Re: How to format cells in DataGrid?
Aug 21, 2008 08:37 AM|LINK
Hi,
Just try to change text opened as "<b>opened</b>" in bold tag.
It may helps.
Kalpana Patel
vinz
All-Star
127077 Points
17946 Posts
MVP
Re: How to format cells in DataGrid?
Aug 21, 2008 08:40 AM|LINK
Try this sample snippet below
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If (e.Item.ItemType = ListItemType.Item) OrElse (e.Item.ItemType = ListItemType.AlternatingItem) Then
If e.Item.Cells(0).Text = "opened" Then
e.Item.Cells(0).Font.Bold = True 'just changed the index of cells based on your requirements
'or this below
e.Item.Cells(0).Attributes.Add("style", "font-weight:bold")
Else
'Do something here
End If
End If
End Sub
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
Amipatel1986
Member
323 Points
99 Posts
Re: How to format cells in DataGrid?
Aug 21, 2008 08:41 AM|LINK
if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer)) { if( e.Item.Cells[4].Text = "opened") { e.Item.Cells[4].Font.Bold = true; }vit0
Member
48 Points
85 Posts
Re: How to format cells in DataGrid?
Aug 21, 2008 09:26 AM|LINK
vinz, Amipatel1986,
You both helped me, thank you, thank you :)