【发布时间】:2017-03-29 05:13:16
【问题描述】:
VB.net webform 将数据从 Sql 数据库拉取到 gridview。
我有两个位列 Rush 和 Normal - 在后面的代码中,如果 Rush 被选中,则行单元格变为红色,Normal 变为蓝色。
我遇到的问题是位是 True 或 False 没有太多运气将它们转换为 Integer 或 Int32。
这是我正在使用的代码,如果单元格 7 不等于 1,此代码会将所有行变为蓝色。
如果我转到 Rush cell(10) 错误输入字符串格式不正确。
问题是如何将位从真/假转换为 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
【问题讨论】:
-
你能把你的aspx页面的代码贴在这里
-
状态表单或插入表单,以及如何在此页面上添加更多代码