2017-03-28 3 views
0

VB.net 웹폼이 Sql 데이터베이스에서 gridview로 데이터를 가져옵니다.VB.net Webform Gridview with checkbox DataControlRowType

두 개의 비트 열이 있습니다. 러시 및 보통 - 코드 뒤에서 러시가 선택되어 있으면 행 셀이 빨간색으로 변하고 보통은 파란색으로 바뀝니다.

내가 가진 문제는 True 또는 False로 Integer 또는 Int32로 변환하는 것이별로 행운이 아님을 나타냅니다. 하지 올바른 형식 I 셀 러쉬로 이동합니다 여기

내가 함께 일하고 코드이며,이 코드는 경우 전지 7 같지 1.

에 모든 행이 파란색으로 (10) 오류 입력 문자열.

질문은 True/false에서 1/0 또는 올바른 형식으로 비트를 변환하는 방법입니다.

Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) 

    If e.Row.RowType = DataControlRowType.DataRow Then 

     Dim sh As String = Convert.ToInt32(e.Row.Cells(7).Text) 

     For Each cell As TableCell In e.Row.Cells 
      If sh = 1 Then 
       cell.BackColor = Drawing.Color.Red 
      Else 
       cell.BackColor = Drawing.Color.Blue 

      End If 

     Next 


    End If 



End Sub 
+0

당신은 어떻게 –

+0

상태 양식을 통해 aspx 페이지의 코드를 게시하거나 삽입하십시오 수 있습니다 .. 빨간색과 청색 정상 오류 문자열이 유효한 부울로 인식되지 않습니다. – Lookup12

답변

0

은 내가 대신 부울 싸움, 나는 변화에 정수로 세포를 결정, 여기가 생각합니다. 확인하고 생각을 알려주세요. 그것은 작동 는, 러쉬 주문은

Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) 


    If e.Row.RowType = DataControlRowType.DataRow Then 
     Dim Chkb As Integer = (e.Row.DataItem(10)) 

     For Each cell As TableCell In e.Row.Cells 
      If Chkb = -1 Then 
       cell.BackColor = Drawing.Color.Red 
      Else 
       cell.BackColor = Drawing.Color.Blue 

      End If 

     Next 


    End If 



End Sub 
0

비트 열이있을 때 왜 정수로 변환해야합니까? 아래 코드를 사용해보십시오.

Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) 
If e.Row.RowType = DataControlRowType.DataRow Then 
    Dim sh As Boolean = Convert.ToBoolean(e.Row.Cells(7).Text) 
    For Each cell As TableCell In e.Row.Cells 
     If sh Then 
      cell.BackColor = Drawing.Color.Red 
     Else 
      cell.BackColor = Drawing.Color.Blue 
     End If 
    Next 
End If 
End Sub 
+0

예외이 페이지에서 더 많은 코드를 추가 할 양식을 여기 – Lookup12