Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change color text in header of gridview 1

Status
Not open for further replies.

smbrown

Programmer
Mar 30, 2009
15
US
I create a grid using my VB code. I want to change the color of the text in only one of the headers (Problems) in my VB code as well.

Dim myTable As New DataTable()
Dim dc1 As New DataColumn("Year", Type.GetType("System.Int32"))
Dim dc8 As New DataColumn("Problems", Type.GetType("System.Int32"))
myTable.Columns.Add(dc1)
myTable.Columns.Add(dc2)
Dim myRow As DataRow
For i = 0 To r.Length - 1
myRow = myTable.NewRow
myRow(dc1) = r(i)
myRow(dc2) = s(i)
myTable.Rows.Add(myRow)

Any help would be great!
Thanks,
SMBrown
 
Where is the grid? You are just creating a datatable. Are you binding the grid to the datatable you are creating?
You can change the text color in the RowDataBound event of the grid.
 
Sorry.
The data from the table is bound to a gridview in the front end of the web page.

Do you have an example of the syntax used to do this?
I haven't been able to get anything that I have found to work. They all just change the entire header or the footer. I just want to change the color of one of the column headers not all of them.

Thanks,
SMBrown
 
Off the top of my head:
In the RowDataBound event, check the e.row.rowtype. If it's the header row, find the column you want and change the backcolor or use .attributes.add to add a css style. Post back if you need more help. That should get you going.
 
If e.Row.RowType = DataControlRowType.Header Then
e.Row.Cells(1).ForeColor = Drawing.Color.CornflowerBlue
End If

This works if I want to change the font color of the whole column.
The column header says:
# of Problems
I only want to change the "Problems" to red font, and the "# of" to stay black.
I don't think that I gave enough info in my first post.
Sorry again.

Thanks,
SMBrown
 
e.Row.Cells(1).Text gets the text of the column header. Look up string functions in help to figure out how to grab only part of the string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top