Setting a DataGrid row/column format programmatically in ASP.NET

zoobird
zoobird used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Here is a nice little article in MSDN..

http://msdn.microsoft.com/msdnmag/issues/01/12/asp/asp0112.asp

Naveen

Author

Commented:
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

Author

Commented:
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.
Question abandoned by Experts; points refunded and question closed.

Netminder
EE Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial