返回首页

我有一个ListView,我想改变在细胞值的行的背景颜色。

我可以修改每个项目的ForeColor属性,但我有没有运气行。

Private Sub ListViewTraining_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListViewTraining.ItemDataBound

     Dim list As ListView = TryCast(sender, ListView)

     If e.Item.ItemType = ListViewItemType.DataItem Then

         Dim FormatLabelformating As Label = DirectCast(e.Item.FindControl("FormatLabel"), Label)

         Dim ItemNumberLabelformating As Label = DirectCast(e.Item.FindControl("ItemNumberLabel"), Label)

         Dim TrainingLabelformating As Label = DirectCast(e.Item.FindControl("TrainingLabel"), Label)

         Dim StartDateLabelformating As Label = DirectCast(e.Item.FindControl("StartDateLabel"), Label)

         Dim StopDateLabelformating As Label = DirectCast(e.Item.FindControl("StopDateLabel"), Label)

         Dim TrainedByLabelformating As Label = DirectCast(e.Item.FindControl("TrainedByLabel"), Label)

         Dim UpdateLabelformating As Label = DirectCast(e.Item.FindControl("UpdateLabel"), Label)

         Dim UpdatedByLabelformating As Label = DirectCast(e.Item.FindControl("UpdatedByLabel"), Label)

         'Dim nRow As System.Web.UI.WebControls.TableRow = DirectCast(e.Item.FindControl("ItemRow"), System.Web.UI.WebControls.TableRow) tried this but I get can't convert to System.Web.UI. Webcontrols

         If Not IsNothing(FormatLabelformating) Then

             If FormatLabelformating.Text = "h" Then

 



                 ListViewTraining.Items(e.Item).BackColor = Color.Aqua

 

                 FormatLabelformating.ForeColor = Color.DarkBlue

                 FormatLabelformating.Font.Bold = True

                 ItemNumberLabelformating.ForeColor = Color.DarkBlue

                 ItemNumberLabelformating.Font.Bold = True

                 TrainingLabelformating.ForeColor = Color.DarkBlue

                 TrainingLabelformating.Font.Bold = True

                 StartDateLabelformating.ForeColor = Color.DarkBlue

                 StartDateLabelformating.Font.Bold = True

                 StopDateLabelformating.ForeColor = Color.DarkBlue

                 StopDateLabelformating.Font.Bold = True

                 TrainedByLabelformating.ForeColor = Color.DarkBlue

                 TrainedByLabelformating.Font.Bold = True

                 UpdateLabelformating.ForeColor = Color.DarkBlue

                 UpdateLabelformating.Font.Bold = True

                 UpdatedByLabelformating.ForeColor = Color.DarkBlue

                 UpdatedByLabelformating.Font.Bold = True

             Else

                 FormatLabelformating.ForeColor = Color.Black

                 FormatLabelformating.Font.Bold = False

                 ItemNumberLabelformating.ForeColor = Color.Black

                 ItemNumberLabelformating.Font.Bold = False

                 TrainingLabelformating.ForeColor = Color.Black

                 TrainingLabelformating.Font.Bold = False

                 StartDateLabelformating.ForeColor = Color.Black

                 StartDateLabelformating.Font.Bold = False

                 StopDateLabelformating.ForeColor = Color.Black

                 StopDateLabelformating.Font.Bold = False

                 TrainedByLabelformating.ForeColor = Color.Black

                 TrainedByLabelformating.Font.Bold = False

                 UpdateLabelformating.ForeColor = Color.Black

                 UpdateLabelformating.Font.Bold = False

                 UpdatedByLabelformating.ForeColor = Color.Black

                 UpdatedByLabelformating.Font.Bold = False

 

             End If

         End If

     End If

 End Sub

ASP的:
 60; LT; ItemTemplategt;
&# 160; LT,TR ID ="ItemRow"RUNAT ="服务器"的风格="背景颜色:#FFFFFF的颜色:#000000;"GT
  ; LT TD风格="宽度:50像素"GT
  ; 文本="删除"/ GT
 0; &# 160; LT ;/ tdgt;
& #160; LT; tdgt;
&# 160; &# 160; 文字='<%#EVAL(ItemNumber的")%GT / GT'
LT ;/ tdgt;
 0; LT; tdgt;
 0; 文字='<%#的Eval("培训")%GT / GT'
& #160; LT ;/ tdgt;
LT; tdgt;
& #160; & #160; 文字='<%#的Eval("起始日期","{0:DD MMM的年}")%GT / GT'
 0; LT ;/ tdgt;
 60; LT; tdgt;
 0; 文字='<%#的Eval("StopDate","{0:DD MMM的年}")%GT / GT'
 0; LT ;/ tdgt;
 60; LT; tdgt;
 0;  0; LT ;/ tdgt;
&# 160; LT; tdgt;
 0;  60; LT ;/ tdgt;
&# 160; LT; tdgt;
 60; & #160; LT ;/ tdgt;
LT; tdgt;
& #160; '/>
 60; LT ;/ tdgt;
& #160; LT ;/ trgt;
LT ;/ ItemTemplategt;
任何想法?|安迪・莫里斯:​​| O型Ghareeb:上ListViewTraining_ItemDataBound添加此代码来改变它; TRgt;背景色:
        If e.Item.ItemType = ListViewItemType.DataItem Then

            Dim dataitem As ListViewDataItem = DirectCast(e.Item, ListViewDataItem)

            Dim tr As System.Web.UI.HtmlControls.HtmlTableRow

            tr = DirectCast(dataitem.FindControl("ItemRow"), System.Web.UI.HtmlControls.HtmlTableRow)

            tr.BgColor = "#FF0000"

        End If

回答