highlight a datagrid template row?

G

Guest

I've searched, reviewed, and attempted dozens of code ideas on the subject. I
can't seem to get something that seems so simple to work. To highlight a row
in a datagrid based on another value in that row.

I have a datagrid using Template and Item Columns, i.e.:

<asp:TemplateColumn HeaderText="CA Date Req"
HeaderStyle-CssClass="gridqtext" ItemStyle-CssClass="gridtext">
<ItemTemplate>
<asp:Label ID="lblcadatereq" CssClass="gridtext" width="75" Runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "Concern_DCADate", "{0:d}") %>'
Visible="True">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

I've tried both Oncreate and OnDataBound, no luck. I have several columns,
but I need values from checkbox (#3) and Label (#4). I've tried, etc.:
CType(E.Item.FindControl("lblcadatereq"), Label).Text

What is strange is that when I run (Onitemcreated):

Response.Write("value = " & e.Item.Cells(4).Text & "<br>")

I get, there are four rows in my grid (header, two data, a blank bottom
row). I get:
#1 value = "Title of Header"
#2 - 4 value = (is blank). The grid shows data in #2 and #3???

I have also ran a routine to remove the first and last rows using:
e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem
but still no values from grid for rows 2 and 3????
 
E

Eliyahu Goldin

It is not clear from the message what is your immediate problem. You can't
get a value of a bound column? Bound columns get value in ItemDataBound
event. Also you can use PreRender event in which the grid is already fully
populated with all values.

Eliyahu
 
T

Tampa.NET Koder

I would say that you were on the right track with the OnItemDataBound Event.
This fires before the binding so basically you can grab values from your
datsource and do some conditional logic. OnItemCreated Event also comes to
mind; but somehow I don't think this would give you a solution for this.
They got to have code sames for this out there.
 
G

Guest

got it! Was using Itemcreated, switch to ItemDataBound and used:
Dim careq As Boolean = CType(e.Item.Cells(3).FindControl("ckcareq"),
CheckBox).Checked
Dim cadate As Date =
CType(e.Item.Cells(4).FindControl("lblcadatereq"), Label).Text
got the values, thanx.!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top