2012-10-03 2 views
2

행을 선택하고 상태가 오프라인 인 경우 빨간색으로 강조 표시하고 싶습니다.ASP VB. NET 하이라이트 행을 붉은 색으로

어떻게 ASP .NET에서이를 수행 할 수 있습니까?

나는 보호 된 void OnRowCreated (개체 보낸 사람, GridViewRowEventArgs e)에 대해 이야기하는 예를 많이 보았습니다.

컨트롤러에 클래스를 생성해야합니까? 또는보기? 아주> _ <

당신은 단지 행이 model에서 Online/Offline status 값 참조하고 행을 강조 따라 CSS을 변경해야합니다

+0

asp.net 웹 양식 또는 asp.net MVC? –

+0

여기에 코드를 넣으십시오. –

답변

0

나는 빨간색으로 방법 CSS의 TD 클래스를 시도,하지만 난 그것을 작동 가져올 수 없습니다. 어떤 생각? 다음과 같은

내 코드 : -

@For Each item In Model 
    Dim currentItem = item 
    Dim status = Html.Action("showPing", New With {.ipaddress = currentItem.IP}) 
    If status.Equals("Online") Then 
     @<tr> 
      <td> 
       @Html.DisplayFor(Function(modelItem) currentItem.Name) 
      </td> 
      <td> 
       @Html.DisplayFor(Function(modelItem) currentItem.IP) 
      </td> 
      <td> 
       @Html.DisplayFor(Function(modelItem) currentItem.Location) 
      </td> 
      <td> 
       @Html.Action("showPing", New With {.ipaddress = currentItem.IP}) 
      </td> 
     </tr> 
    Else 
     @<tr> 
      <td class="red"> 
       @Html.DisplayFor(Function(modelItem) currentItem.Name) 
      </td> 
      <td class="red"> 
       @Html.DisplayFor(Function(modelItem) currentItem.IP) 
      </td> 
      <td class="red"> 
       @Html.DisplayFor(Function(modelItem) currentItem.Location) 
      </td> 
      <td class="red"> 
       @Html.Action("showPing", New With {.ipaddress = currentItem.IP}) 
      </td> 
     </tr> 
    End If 

다음

그것은 모두 빨간를 보였다. ASP .NET VB MVC4

+0

Dim 상태가 변경됨에 따라 String = Html.Action ("showPing", {. ipaddress = currentItem.IP}이 (가) 새로 추가됨) ToString과 이제는 정상적으로 작동합니다! 다들 감사 해요!! – Keat84

0

도와주세요 새로운 MVC에 혼란. 코드가 제공되지 않았기 때문에 나는 예제를 조롱했다 :

즉. 당신의 View에서 다음

public class OnlineOfflineElements { 
    public List<Element> elements { get; set; } 

} 

public class Element { 
    public bool isOnline { get; set; } 
} 

:

@foreach (var status in elements) { 
    if (status.isOnline) { 
     <tr class="Online"> 
    } else { 
     <tr class="Offline"> 
    } 
    // Other model content here 
} 
+0

나는 CSS TD 클래스를 빨간색으로 시도했지만 작동시킬 수있었습니다. – Keat84

0

내 웹 페이지에서 gridview에 대해이 작업을 완료 할 수있게되었습니다. 오프라인 일 때 데이터 행을 빨간색으로 변경할 수 있어야했습니다.

Protected Sub grdName_RowDataBound(ByVal sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdName.RowDataBound 

    If e.Row.RowType = DataControlRowType.DataRow Then 
     If DataBinder.Eval(e.Row.DataItem, "Status").ToString() = "OffLine" Then 
      e.Row.BackColor = System.Drawing.Color.Red 
     End If 
    End If 

    End Sub 

희망이 있습니다.

베티