473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

After DataBind in DataGrid set CssClass per row?

Using ASP.Net v1.1.

In a System.Web.UI.WebControls.DataGrid I can't find any method or property that
looks like it would give one access to individual rows after a DataBind.

What I want to do: Set either CssClass or other properties for a table tr tag for
each row and make them different depending on tests of values in each row.

I figure I can use the corresponding table that had a database bound to the grid to
get at values to test. But I do not see how to set properties at a per row level in
the DataGrid. Is this possible?

Is it any more possible in ASP.Net v2.0?

I want to style each individual row in ways dependent on that row's data values. I do
not see how to do that either before or after the DataBind. Is it possible to do at all?
Jan 18 '06 #1
3 2557
Sure it is possible.

The DataGrid control has Items property. Items represent the rows.

The are 2 standard ways of setting row properties:

1. In PreRender event loop through the myGrid.Items collection.

2. In ItemDataBound event you get access to each individual item, including
the header and footer if any. You get a reference to the item as a parameter
to the event handler.

Eliyahu

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit .com>
wrote in message news:Oz**************@tk2msftngp13.phx.gbl...
Using ASP.Net v1.1.

In a System.Web.UI.WebControls.DataGrid I can't find any method or
property that looks like it would give one access to individual rows after
a DataBind.

What I want to do: Set either CssClass or other properties for a table tr
tag for each row and make them different depending on tests of values in
each row.

I figure I can use the corresponding table that had a database bound to
the grid to get at values to test. But I do not see how to set properties
at a per row level in the DataGrid. Is this possible?

Is it any more possible in ASP.Net v2.0?

I want to style each individual row in ways dependent on that row's data
values. I do not see how to do that either before or after the DataBind.
Is it possible to do at all?

Jan 18 '06 #2
In the ItemDataBound event I'm trying to get access to the dataset row that was used
to populate that table row.

Is e.Item.DataItem the data row? Or is something else?

I want to look at values in the data row and test them and then decide which css to
assign to that row.

Here's an Item_Bound event routine:

void Item_Bound(Object sender, DataGridItemEventArgs e)
{
//e.Item.Cells[2].Text
//e.Item.Cells[2].CssClass
//e.Item.CssClass
// e.Item.DataItem
}

Also, what are the arguments for the PreRender event? Is there some system for
knowing their args or is there a way to get VS 2003 to generate a method that has the
right args?

I'm guessing it is this:
void PreRender(Object sender,System.EventArgs ee)

But I'm not sure.
Eliyahu Goldin wrote:
Sure it is possible.

The DataGrid control has Items property. Items represent the rows.

The are 2 standard ways of setting row properties:

1. In PreRender event loop through the myGrid.Items collection.

2. In ItemDataBound event you get access to each individual item, including
the header and footer if any. You get a reference to the item as a parameter
to the event handler.

Eliyahu

Jan 19 '06 #3
Yes, e.Item.DataItem is the data row.You need to typecast it to the
appropriate type.

For the PreRender event info, why don't you look in the MSDN Library? It is
available online if you don't have it locally. You can setup events in the
aspx page Design view. And you guess is almost right. If you setup the event
in the HTML view, the handler should be declared protected.

Eliyahu

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit .com>
wrote in message news:eb**************@TK2MSFTNGP14.phx.gbl...
In the ItemDataBound event I'm trying to get access to the dataset row
that was used to populate that table row.

Is e.Item.DataItem the data row? Or is something else?

I want to look at values in the data row and test them and then decide
which css to assign to that row.

Here's an Item_Bound event routine:

void Item_Bound(Object sender, DataGridItemEventArgs e)
{
//e.Item.Cells[2].Text
//e.Item.Cells[2].CssClass
//e.Item.CssClass
// e.Item.DataItem
}

Also, what are the arguments for the PreRender event? Is there some system
for knowing their args or is there a way to get VS 2003 to generate a
method that has the right args?

I'm guessing it is this:
void PreRender(Object sender,System.EventArgs ee)

But I'm not sure.
Eliyahu Goldin wrote:
Sure it is possible.

The DataGrid control has Items property. Items represent the rows.

The are 2 standard ways of setting row properties:

1. In PreRender event loop through the myGrid.Items collection.

2. In ItemDataBound event you get access to each individual item,
including the header and footer if any. You get a reference to the item
as a parameter to the event handler.

Eliyahu

Jan 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ante Perkovic | last post by:
Hi, Sorry for opening new topic instead of replying, but this is a completely new issue. I found out that changing one line of code in Page.Load event handler causes a button handler not to...
1
by: Tayo | last post by:
What is best way of having a consistent datagrid format on multiple pages? Any ideas welcome Tayo
0
by: Steve Kallal | last post by:
I have a DataGrid with an EditCommandColumn column set to a type of PushButton. I want to set set CssClass on these buttons and cannot without using code-behind code on the ItemDataBound event. The...
5
by: Eric Caron | last post by:
Hi everyone, I have a web form that asks the user what languages he speaks and what his skill level is. I used a DataGrid control bound to a table that contains the languages and three template...
1
by: marc-andr? | last post by:
Hi, I have to loop on each control on a webforms... I use this function : public void LoopOnAllControls(ControlCollection coll) { foreach (System.Web.UI.Control ctrl in coll) {
0
by: MattC | last post by:
Hi, I have place the following code in my ItemDataBound event: The problem I have is that when I select a row for editing using the edit command it no longer changes the CSSClass to the one...
2
by: Liza | last post by:
Hi I have a problem gettting the right data in my CommandArgument after I applyed a rowfilter. My template column looks somewhat like this: <asp:TemplateColumn HeaderText="ErrorID">...
4
by: Joe | last post by:
Hello, I have a datagrid in an nested html table (one table inside of another table) and have set the allowsSorting property to true. I've created in the code-behind a method (Sub - I'm using...
2
by: Ray Booysen | last post by:
Hi all I have a collection of Invoices that I bind to a datagrid. Some of these invoices have been processed and you can tell this via a property in the invoice class called DateProcessed. If...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.