How to specified datagrid's row backcolor
-
As my articles in datagrid has different status,so i want to differ them by different backcolor,that is i want a record displayed in datagrid changed its backcolor by its status. Looking forward to your reply. Thanks a lot!
-
As my articles in datagrid has different status,so i want to differ them by different backcolor,that is i want a record displayed in datagrid changed its backcolor by its status. Looking forward to your reply. Thanks a lot!
You will have to do it in the ItemDataBound event. Every row that is created will fire this event before creating the actual row.
private grid_ItemDataBound(Byval sender as system.object, byval e as DataGridItemEventArgs) handles grid.ItemDataBound
If e.item.itemtype = ListItemType.Item or ListItemType.AlternatingItem then
'You can do this
dim r as TableCellCollection = e.item.Cells
r.item(0).BackColor = Color.Coral
'or
i = 0
e.item.cells(i).BackColor = Color.FireBrick
End if
end subOops, I thought I was in the ASP.Net section. However, this still may be helpful. Hope this helps, Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)
-
You will have to do it in the ItemDataBound event. Every row that is created will fire this event before creating the actual row.
private grid_ItemDataBound(Byval sender as system.object, byval e as DataGridItemEventArgs) handles grid.ItemDataBound
If e.item.itemtype = ListItemType.Item or ListItemType.AlternatingItem then
'You can do this
dim r as TableCellCollection = e.item.Cells
r.item(0).BackColor = Color.Coral
'or
i = 0
e.item.cells(i).BackColor = Color.FireBrick
End if
end subOops, I thought I was in the ASP.Net section. However, this still may be helpful. Hope this helps, Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)
I have solved my problem by your hints.Perhaps I didn't express my problem very well. Anyhow,thanks a lot. Following are my code: :-O:-O Sub dgArticles_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Dim item As DataGridItem For Each item In dgArticles.Items 'put your judge condition here 'assumed it return 1 and 2 Select Case CurrentStatus Case "1" item.BackColor = Color.Coral Case "2" item.BackColor = Color.Beige Case Else 'do nothing End Select Next item end sub I hope I can get your help when i am in need on program. May you happy!