By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,562 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,562 IT Pros & Developers. It's quick & easy.

highlight a datagrid template row?

P: n/a
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????

Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
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????

Nov 19 '05 #2

P: n/a
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.
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
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????

Nov 19 '05 #3

P: n/a
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.
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
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????

Nov 19 '05 #4

P: n/a
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.!

"Eliyahu Goldin" wrote:
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

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
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????


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.