Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
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.
 
Share this answer
 
Comments
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
Try
cmd.Connection = cn
cn.Open()
da = New SqlDataAdapter("select * from facsort", cn)
tb2 = New DataTable
da.Fill(tb2)
FacsortDataGridView.DataSource = tb2


Catch ex As Exception
MsgBox(ex.Message)
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 vb.net 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;
Next
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 ']]
CSS
.gridcss
{
background:Red;
color:White;
}



VB
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
 
Share this answer
 
v4
Comments
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900