Connecting Tech Pros Worldwide Forums | Help | Site Map

highlight a datagrid template row?

Chris
Guest
 
Posts: n/a
#1: Nov 19 '05
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????


Eliyahu Goldin
Guest
 
Posts: n/a
#2: Nov 19 '05

re: highlight a datagrid template row?


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" <Chris@discussions.microsoft.com> wrote in message
news:3656552F-4B4B-482A-A5A8-E41906EB7981@microsoft.com...[color=blue]
> I've searched, reviewed, and attempted dozens of code ideas on the[/color]
subject. I[color=blue]
> can't seem to get something that seems so simple to work. To highlight a[/color]
row[color=blue]
> 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}")[/color]
%>'[color=blue]
> 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????
>[/color]


Tampa.NET Koder
Guest
 
Posts: n/a
#3: Nov 19 '05

re: highlight a datagrid template row?


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" <Chris@discussions.microsoft.com> wrote in message
news:3656552F-4B4B-482A-A5A8-E41906EB7981@microsoft.com...[color=blue]
> 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????
>[/color]


Tampa.NET Koder
Guest
 
Posts: n/a
#4: Nov 19 '05

re: highlight a datagrid template row?


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" <Chris@discussions.microsoft.com> wrote in message
news:3656552F-4B4B-482A-A5A8-E41906EB7981@microsoft.com...[color=blue]
> 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????
>[/color]


Chris
Guest
 
Posts: n/a
#5: Nov 19 '05

re: highlight a datagrid template row?


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:
[color=blue]
> 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" <Chris@discussions.microsoft.com> wrote in message
> news:3656552F-4B4B-482A-A5A8-E41906EB7981@microsoft.com...[color=green]
> > I've searched, reviewed, and attempted dozens of code ideas on the[/color]
> subject. I[color=green]
> > can't seem to get something that seems so simple to work. To highlight a[/color]
> row[color=green]
> > 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}")[/color]
> %>'[color=green]
> > 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????
> >[/color]
>
>
>[/color]
Closed Thread