Click here to Skip to main content
13,045,790 members (46,558 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 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 8-Jul-13 6:10am
After grid bind code:
FacsortDataGridView.DataSource = tb2
sudeshna from bangkok 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 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 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 8-Jul-13 6:32am
where to use drv variable.its showing error on drv.
Nirav Prabtani 8-Jul-13 6:38am
try without declaring drv ... :)
sudeshna from bangkok 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 8-Jul-13 6:56am
Try my updated solution.
sudeshna from bangkok 8-Jul-13 7:03am
no property is there like rowdatabound in the declarations
Nirav Prabtani 8-Jul-13 7:06am
try this link....:)
sudeshna from bangkok 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2017
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