没有人de

昨天不能唤回来,明天还不确实,而能确有把握的就是今天。今日一天,当明日两天。 -- 耶曼逊

博客园 首页 新随笔 联系 订阅 管理
改变datagrid中行颜色

Private Sub dgrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgrid.ItemDataBound

If Not e.Item.ItemIndex = -1 Then
e.Item.Attributes.Add("onmouseover", "this.setAttribute('BKC',this.style.backgroundColor);this.style.backgroundColor='#EEEEEE'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.getAttribute('BKC');")
End If

Dim FolderID As String = Request.QueryString("FolderID")
End Sub

在DataGrid新增一序号列,即类似Excel中的行号
添加模板列
<Columns>
<asp:TemplateColumn HeaderText="" ItemStyle-Width="50">
<ItemTemplate>
<%# Container.ItemIndex+1 %>
</ItemTemplate>
</asp:TemplateColumn>
</column>


实现datagrid 多列求和

Sub DataGrid_DataBound(obj as object,e as DataGridItemEventArgs)
Dim intTotal as integer
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
Dim lbl_id as label=e.item.findControl("lbl_id")
intTotal+=cDbl(lbl_id.text)
Case listItemType.footer
e.item.cells(0).text="总计:" & intTotal.tostring
e.item.cells(0).Attributes.add("Align","center")
End Select
End Sub
一。其中e.item.findControl("lbl_id")的lbl_id是dataGrid中一行的一个文本框或标签;
二。加在DataGrid中的OnItemDataBound="DataGrid_DataBound"事件中;


datagrid中根据不同的值显示不同的颜色

Private Sub grdcheckequipment_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdcheckequipment.ItemDataBound
' 确保处理的是数据行,而不是Header或者Footer
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
' 得到Manager字段的值
Try
Dim isManager As DateTime = CType(DataBinder.Eval(e.Item.DataItem, "首次接入时间"), DateTime)
If isManager = "1900-01-01" Then
e.Item.Cells(6).ForeColor =color.red
End If
Catch
End Try


End If
End Sub
----------------------------------------

在DataGrid中如何设定其中某一列的背景色,还有如何设定某一单元格的背景色


自定义列,设置列属性为<ItemStyle ForeColor="Red" BackColor="Yellow"></ItemStyle>
posted on 2005-01-08 17:14  没有人  阅读(194)  评论(0编辑  收藏  举报