2012-07-24 5 views
2

바인드 된 Gridview가 있습니다.Gridview에서 가장 큰 값을 강조 표시하는 방법

그리고 중복이 있어도 가장 긴 리드 타임의 글꼴 색을 변경하고 싶습니다. if 문을 작성하는 방법에 대해서는 잘 모른다.

이 코드가 잘못 되었음에도 불구하고 이것은 내가하고 싶은 대략적인 아이디어입니다.

if Max(LeadTime) Then 

GridView.ForeColor = Color.Red 

아무도 도와 줄 수 있습니까?

답변

3

먼저 데이터 소스에서 최대 값을 가져와야합니다. 이벤트 핸들러를 결합하여 항목 데이터에서

maxLeadTime = ds.Max(dsi => dsi.LeadTime) 

최대 값으로 바인딩 된 항목을 비교 : 당신은 LINQ이 할 수

if (item.LeadTime == maxLeadTime) 
{ 
    /* do stuff */ 
} 
+0

죄송 페이지로드에서

(T의) 목록에 바인딩하는 경우

Private maxVal As Decimal Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Me.Page.IsPostBack Then dim dt as datatable = GetTable() maxVal = ds.AsEnumerable.Max(Function(dr) dr("lead_time")) gv.DataSource = dt gv.DataBind() End If End Sub Private Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim dr As DataRowView = e.Row.DataItem If dr("lead_time") = maxVal Then e.Row.BackColor = Drawing.Color.Red End If End If End Sub 

동일한 것 DSi가 무엇인지 알 수 있습니까? –

+0

dsi는 [lambda expression] (http://msdn.microsoft.com/en-us/library/bb397687.aspx)에 전달 된 항목의 별칭입니다. –

0

(VB.NET 버전) 당신에게 가정하면 그리드를 바인딩 datatable에, 당신이 그것을 어떻게 할 것입니다. 행 데이터 바인딩에서

maxVal = urList.Max(Function(x) x.LeadTime) 

:

Dim uc As urClass = e.Row.DataItem 
     If uc.LeadTime = maxVal Then 
      e.Row.BackColor = Drawing.Color.Red 
     End If 
관련 문제