[英]I have 1 textbox and checkbox in webform1 and one textbox in seconf webform in vb.net !
[英]VB.net Webform Gridview with checkbox DataControlRowType
VB.net Webform將數據從Sql數據庫提取到gridview。
我有兩個位列Rush和Normal-在后面的代碼中,如果選中Rush,則行單元格變為紅色,Normal變為藍色。
我的問題是,位是True還是False,將它們轉換為Integer或Int32的運氣不好。
這是我正在使用的代碼,如果單元格7不等於1,此代碼會將所有行變為藍色。
如果我轉到Rush cell(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
為什么要轉換為整數,當您有位列時,請嘗試以下代碼。
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
我想在這里有它,而不是與布爾值作斗爭,我決定將單元格更改為Integer。 請檢查並讓我知道您的想法。 它正常工作,緊急訂單為紅色,正常為藍色..
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.