Click here to Skip to main content
11,796,774 members (67,177 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
i have one form where columns are name,type,size,date.

the data displays in gridview.

i want all the rows of date column to get in red colour.

how to change that in properties

Will be obliged if anyone can help me.

thanks in advance
Posted 7-Jul-13 23:25pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

for (int i = 0; i < gridview1.Rows.Count; i++)
                gridview1.Rows[i].Cells[gridview1.Columns.Count - 1].BackColor = Color.Red;

Accept as answer and vote if help.
sudeshna from bangkok at 8-Jul-13 6:04am
thanks for the reply but where should i write this code?

under button_click?

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=record;user=sa;password=gariahat")
Dim da As New SqlDataAdapter
Dim cmd As New SqlCommand
Dim ds As New DataSet
Dim tb2 As DataTable
Dim i As Integer
cmd.Connection = cn
da = New SqlDataAdapter("select * from facsort", cn)
tb2 = New DataTable
FacsortDataGridView.DataSource = tb2

Catch ex As Exception
End Try
jaideepsinh at 8-Jul-13 6:10am
After grid bind code:
FacsortDataGridView.DataSource = tb2
sudeshna from bangkok at 8-Jul-13 6:34am
can you write the code in 2008. i am using this version. so showing error in 1st for loop statement
jaideepsinh at 8-Jul-13 7:30am
For i As Integer = 0 To Me.DataGridView1.Rows.Count - 1
DataGridView1.Rows[i].Cells[DataGridView1.Columns.Count - 1].BackColor = Color.Red;
sudeshna from bangkok at 8-Jul-13 22:38pm
DataGridView1.Rows[i].Cells[DataGridView1.Columns.Count - 1].BackColor = Color.Red;

this full line is showing error.

cells is not a member of integer
bracketed identifier is missing ']]
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


Protected Sub gvdata_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(3).CssClass = "gridcss"
End If
End Sub
sudeshna from bangkok at 8-Jul-13 6:32am
where to use drv variable.its showing error on drv.
Nirav Prabtani at 8-Jul-13 6:38am
try without declaring drv ... :)
sudeshna from bangkok at 8-Jul-13 6:49am
your code is selecting my 3rd row and making it full red.

but i want only the last column all data(rows) to be red.that is only the textcolor.
Nirav Prabtani at 8-Jul-13 6:56am
Try my updated solution.
sudeshna from bangkok at 8-Jul-13 7:03am
no property is there like rowdatabound in the declarations
Nirav Prabtani at 8-Jul-13 7:06am
try this link....:)
sudeshna from bangkok at 8-Jul-13 22:51pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 480
1 Abhinav S 369
2 OriginalGriff 360
3 CPallini 285
4 KrunalRohit 249
0 OriginalGriff 2,032
1 Maciej Los 1,725
2 KrunalRohit 1,310
3 CPallini 1,055
4 ppolymorphe 883

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100