zoobird
asked on
Setting a DataGrid row/column format programmatically in ASP.NET
I am new to the .NET platform. I have created a DataGrid whose DataSource is a table I create programatically. I want to be able to programatically manipulate the style of the column and rows of the datagrid, such as be able to create a hyperlink column, or make an entire row's font color Red. I am using C#. How do I do this? Please provide a code sample.
ASKER
It's a good article, but it doesn't answer my problem. I need specifics on how to change the properties of certain columns and rows.
There are couple of things that you can do..
.. Following code will set each line's backgrund color to red. But you can manipulate other propeties too.
private void SetEachRowRed()
{
myGrid.ItemStyle.BackColor = Color.Red;
}
If you want to manipulate different columns. Then what you can do is, set AutoGenaretColumns attribute of grid to false and then add BoundColumn or other columns explicitly. This way you will be able to control each column's controls. And this will also fill the Columns collection of grid for manipulating later on.
Take a look at the following link.
http://www.pardesiservices.com/Softomatix/DGAutoGen.asp
Naveen
.. Following code will set each line's backgrund color to red. But you can manipulate other propeties too.
private void SetEachRowRed()
{
myGrid.ItemStyle.BackColor
}
If you want to manipulate different columns. Then what you can do is, set AutoGenaretColumns attribute of grid to false and then add BoundColumn or other columns explicitly. This way you will be able to control each column's controls. And this will also fill the Columns collection of grid for manipulating later on.
Take a look at the following link.
http://www.pardesiservices.com/Softomatix/DGAutoGen.asp
Naveen
ASKER
Naveen,
The thing is, I want to change a random row's background color, not all of the rows, nor alternating rows. I want to highlight certain rows if they meet a set of criteria.
The thing is, I want to change a random row's background color, not all of the rows, nor alternating rows. I want to highlight certain rows if they meet a set of criteria.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://msdn.microsoft.com/msdnmag/issues/01/12/asp/asp0112.asp
Naveen