2017-08-24 10 views
0

データセット(画像添付)の11番目の列の番号に基づいて行を強調表示しようとしています。私は11列目の値が< 5000であるすべての行が赤く強調表示されると考えています。以下は私のコードです:デバッグにRowDataBound行のハイライト

Protected Sub loadData()  
     gvRsrvtionValdtn.DataSource = ds 
       Dim myTable As System.Data.DataRowCollection 
       myTable = ds.Tables(0).Rows 
       If myTable.Count > 0 Then 
        For i = 0 To myTable.Count - 1 
         If myTable(i)(10) > 5000 Then 
          alist.Add(i) 
         End If  
       Next 
      End If 

      gvRsrvtionValdtn.DataBind() 
      btnExp.Visible = True 
     End Sub 
    Protected Sub gvRsrvtionValdtn_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvRsrvtionValdtn.RowDataBound 
      Dim myRow As TableRow = e.Row() 
      If alist.Contains(e.Row.RowIndex) Then 
       myRow.BackColor = Color.Red 
      End If 
     End Sub 



<asp:GridView ID="gvRsrvtionValdtn" runat="server" AutoGenerateColumns="False" 
       BackColor="Black" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
       CellPadding="4" CssClass="aspdatagrid" ForeColor="Black" CellSpacing="1" 
       HeaderStyle-CssClass="fixHdr" Width="98%" EmptyDataText="No records found" 
       EmptyDataRowStyle-CssClass="emptyData" RowStyle-Wrap="false" 
       **OnRowDataBound ="gvRsrvtionValdtn_RowDataBound"**> 

、私は列の11番目の値alistを入力< 5000でレコードを表示することができますが、表示上で強調表示されませんでした。お知らせ下さい。

[my data set][1] 


    [1]: https://i.stack.imgur.com/gm7n8.jpg 

答えて

0

ここでは、達成しようとしていることの最小限の実例を示します。 以下のスニペットでは、列2が100未満の行が異なる色になります。

のWebForm1.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="HighlightRowsInDGV_Web.WebForm1" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div>below this<br /> 
     <asp:GridView ID="gvRsrvtionValdtn" runat="server" AutoGenerateColumns="true" 
       BackColor="green" BorderColor="#DEDFDE" BorderStyle="Double" BorderWidth="1px" 
       CellPadding="4" CssClass="aspdatagrid" ForeColor="Black" CellSpacing="1" 
       HeaderStyle-CssClass="fixHdr" Width="98%" EmptyDataText="No records found" 
       EmptyDataRowStyle-CssClass="emptyData" RowStyle-Wrap="false" 
       OnRowDataBound ="gvRsrvtionValdtn_RowDataBound"></asp:GridView> 

    </div> 
    </form> 
</body> 
</html> 

WebForm1.aspx.vb

Imports System.ComponentModel 

Public Class WebForm1 
    Inherits System.Web.UI.Page 
    Public alist As New BindingList(Of entry) 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
     Dim oneentry As New entry() 
     oneentry.blah = "blah blah blah 1" 
     oneentry.bleh = 50 

     Dim anotherEntry As New entry() 
     anotherEntry.blah = "blah blah blah 2" 
     anotherEntry.bleh = 100 

     Dim yetagain As New entry() 
     yetagain.blah = "blah blah blah 3" 
     yetagain.bleh = 25 

     alist.Add(oneentry) 
     alist.Add(anotherEntry) 
     alist.Add(yetagain) 
     loadData() 
    End Sub 


    Protected Sub loadData() 
     gvRsrvtionValdtn.DataSource = alist 
     gvRsrvtionValdtn.DataBind() 
    End Sub 
    Protected Sub gvRsrvtionValdtn_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvRsrvtionValdtn.RowDataBound 
     Dim ref As Integer = 100 
     If e.Row.RowIndex > -1 Then 'if this is not the header row 
      If CType(e.Row.Cells(1).Text, Integer) < 100 Then 
       e.Row.BackColor = Drawing.Color.AliceBlue 
      End If 
     End If 
    End Sub 

    Public Class entry 
     Public Property blah As String 
     Public Property bleh As Integer 
    End Class 

End Class 

ここにあなたのコメント次の更新方法があります。あなたの質問や問題は少し不明です。あなたのオープニングの質問鉱山はそれをしていますが、スニペットが何をするかだそれ

...列のデータが5000よりも小さい場合、その行をハイライト...

を語ります100よりも100 ...

Protected Sub gvRsrvtionValdtn_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gvRsrvtionValdtn.RowDataBound 
    Dim ref As Integer = 100 
    If e.Row.RowIndex > -1 Then 'if this is not the header row 
     'If CType(e.Row.Cells(1).Text, Integer) < 100 Then 
     ' e.Row.BackColor = Drawing.Color.AliceBlue 
     'End If 
     If alist.Contains(e.Row.DataItem) And CType(e.Row.DataItem, entry).bleh < 100 Then 
      e.Row.BackColor = Drawing.Color.AliceBlue 
     End If 
    End If 

End Sub 
+0

ブレイズ - あなたの入力に感謝を。しかし、データ(行)がgvRsrvtionValdtn_RowDataBoundの自分のalistに収集されていることを知っているので、私は自分のコードを動作させたい。問題はそれらを表示する方法です。あなたは何か考えていますか? – VBlearning

+0

変更されたメソッドを追加しました。実際のコードで作業したい場合は、実際のコードを入力する必要があります。新しいプロジェクトで指定したコードを貼り付けると、欠落しているものが表示されます。あなたのスニペットには、 'alist'と' ds'は何も表示されません。 –

+0

474199 | \t PEDERSL | 4/12/2013 13:19 | \t 6/1/2013 0:00 \t | 189 | \t QC-7/6013パワープレート| |銅ブラス販売| | \t -1 | \t未定義レポートフローパス| \t 15000 | \t 41300 | \tはい\t |はい – VBlearning

0

ローレベルにアクセスするのを忘れました。この行を追加した後:テーブルセルとして、各セルのmyRow.Cellsで保護されたサブgvRsrvtionValdtn_RowDataBoundの声明は、それが動作し内部の場合:

Protected Sub gvRsrvtionValdtn_RowDataBound(sender As Object, e As 
GridViewRowEventArgs) 
    Dim myRow As TableRow = e.Row() 
    If e.Row.RowIndex > -1 Then 
     If alist.Contains(e.Row.RowIndex) Then 
      For Each cell As TableCell In myRow.Cells 
       cell.BackColor = Color.Red 
      Next 
     End If 
    End If 
End Sub 
関連する問題