vb.net通过列中的值显示不同的行颜色

hexiaowu 2010-04-01 10:22:43
gridview中通过一个列isdel=0或1来设置该行的颜色,例如:我isdel=0的时候,该行为红色,isdel=1的时候,该行为绿色,请问大家该怎么做啊,我想在GridView1_DataBound事件下写,网上找的都是鼠标经过,点击这些,大家帮帮忙。还有我是用vb写的,如果是C#的提示下怎么改。谢谢
...全文
141 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hexiaowu 2010-04-07
  • 打赏
  • 举报
回复
虽然自己解决了,但分数还是要给,小弟没分了,谁送点给我呀!
wuyq11 2010-04-02
  • 打赏
  • 举报
回复
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Convert.ToInt32(((Label)e.Row.Cells[2].FindControl("lbl")).Text) > 1)
e.Row.BackColor = System.Drawing.Color.Red;
}
}
leno520213 2010-04-02
  • 打赏
  • 举报
回复
.....................................................................
鲁虾 2010-04-02
  • 打赏
  • 举报
回复
网页上可以用界面设!!
netbandit 2010-04-02
  • 打赏
  • 举报
回复
楼上的都是高手,我也过来学习学习
hztltgg 2010-04-01
  • 打赏
  • 举报
回复
网上那些是要有动态效果才有,移动以后变化的方式,如果你的只是静态显示颜色,不要求变化,那你的方法就可以了,要不去掉if语句,颜色作为变量转换后直接赋值,不过意义不大。
hexiaowu 2010-04-01
  • 打赏
  • 举报
回复
发了贴子,自己突然就有想法了,郁闷,我的方法是
For i = 0 To GridView1.Rows.Count - 1
Dim BZ As String = GridView1.DataKeys(i).Item(5).ToString
If BZ = 0 Then
GridView1.Rows(i).BackColor = System.Drawing.Color.Yellow
Else
GridView1.Rows(i).BackColor = System.Drawing.Color.Blue
end if
next
大家还有什么更好的方法还请赐教啊!
hurtsobad 2010-04-01
  • 打赏
  • 举报
回复
Public Sub InitializemeUser(ByRef objDataGridView As DataGridView)
objDataGridView.AllowUserToAddRows = False
objDataGridView.AllowUserToDeleteRows = False
objDataGridView.AllowUserToResizeColumns = True
objDataGridView.AllowUserToResizeRows = False
objDataGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.AntiqueWhite
'objDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
objDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
objDataGridView.ColumnHeadersHeight = 33
objDataGridView.EditMode = DataGridViewEditMode.EditProgrammatically
objDataGridView.Font = New Font("Arial", 8.25, FontStyle.Regular, GraphicsUnit.Point)
objDataGridView.MultiSelect = False
'objDataGridView.ReadOnly = True
objDataGridView.RowHeadersWidth = 24
objDataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing
objDataGridView.RowsDefaultCellStyle.BackColor = Color.Ivory
objDataGridView.RowTemplate.Height = 18
objDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect
'objDataGridView.ShowCellToolTips = False
End Sub
lixunmeng 2010-04-01
  • 打赏
  • 举报
回复
我这样写的,不知道是不是合适,希望高手指正
Private Sub dvg库存图纸_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dvg库存图纸.CellValueChanged
With dvg库存图纸
If e.RowIndex <= .Rows.Count - 1 Then
If .Rows(e.RowIndex).Cells("库存数量").Value = 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.White
ElseIf .Rows(e.RowIndex).Cells("库存数量").Value <> 0 And .Rows(e.RowIndex).Index Mod 2 = 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.YellowGreen
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
ElseIf .Rows(e.RowIndex).Cells("库存数量").Value <> 0 And .Rows(e.RowIndex).Index Mod 2 <> 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.GreenYellow
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
End If
End If
End With
End Sub
lixunmeng 2010-04-01
  • 打赏
  • 举报
回复
Private Sub dvg库存图纸_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dvg库存图纸.CellValueChanged
With dvg库存图纸
If e.RowIndex <= .Rows.Count - 1 Then
If .Rows(e.RowIndex).Cells("库存数量").Value = 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.White
ElseIf .Rows(e.RowIndex).Cells("库存数量").Value <> 0 And .Rows(e.RowIndex).Index Mod 2 = 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.YellowGreen
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
ElseIf .Rows(e.RowIndex).Cells("库存数量").Value <> 0 And .Rows(e.RowIndex).Index Mod 2 <> 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.GreenYellow
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
End If
End If
End With
End Sub
fina1982 2010-04-01
  • 打赏
  • 举报
回复
按流程来看 你的方法已经是正解了

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧