473,387 Members | 1,542 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,387 software developers and data experts.

CSS of tag, within a Repeater ItemTemplate

JJ
I'm sure this is quite simple, but clearly not for me today:

How do you set the CSS Style of a tag in a repeater Item Template?

e.g. I have this repeater:

<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><a href=' '>Some Text Here</a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
....and I want to change the class of the '<li>' tag in the ItemTemplate
based on a query string setting:
protected void rpt_SubCategoryList_ItemCreated(Object Sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
//if current query string is x and is the same as
the current repeater item ID then
// set the cssclass of the ItemTemplate's <litag
to "myCssClass"
}

}

I am not sure how I access the itemTemplate's tags?

Thanks in advance

JJ
Apr 3 '07 #1
7 12106
On 3 Kwi, 15:36, "JJ" <a...@xyz.comwrote:
I'm sure this is quite simple, but clearly not for me today:

How do you set the CSS Style of a tag in a repeater Item Template?
Maybe try this:

<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li class="yourCSSClass"><a href=' '>Some Text Here</a></li>
<-----------------
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
Apr 3 '07 #2
JJ
Sorry I should have worded that differently:

How do I _change_ the css class of the tag.

Basically the css class of the tag in the repeater item needs to be
programmatically set whenever the repeater loads.

"dtarczynski" <dt*********@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
On 3 Kwi, 15:36, "JJ" <a...@xyz.comwrote:
>I'm sure this is quite simple, but clearly not for me today:

How do you set the CSS Style of a tag in a repeater Item Template?

Maybe try this:

<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li class="yourCSSClass"><a href=' '>Some Text Here</a></li>
<-----------------
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>


Apr 3 '07 #3
add an id and runat=server on the <lithen you can use Item.FindControl
from the onitemdatbound event.

-- bruce (sqlwork.com)

JJ wrote:
I'm sure this is quite simple, but clearly not for me today:

How do you set the CSS Style of a tag in a repeater Item Template?

e.g. I have this repeater:

<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><a href=' '>Some Text Here</a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
...and I want to change the class of the '<li>' tag in the ItemTemplate
based on a query string setting:
protected void rpt_SubCategoryList_ItemCreated(Object Sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
//if current query string is x and is the same as
the current repeater item ID then
// set the cssclass of the ItemTemplate's <litag
to "myCssClass"
}

}

I am not sure how I access the itemTemplate's tags?

Thanks in advance

JJ

Apr 3 '07 #4
On Apr 3, 11:28 am, bruce barker <nos...@nospam.comwrote:
add an id and runat=server on the <lithen you can use Item.FindControl
from the onitemdatbound event.

-- bruce (sqlwork.com)

JJ wrote:
I'm sure this is quite simple, but clearly not for me today:
How do you set the CSS Style of a tag in a repeater Item Template?
e.g. I have this repeater:
<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><a href=' '>Some Text Here</a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
...and I want to change the class of the '<li>' tag in the ItemTemplate
based on a query string setting:
protected void rpt_SubCategoryList_ItemCreated(Object Sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
//if current query string is x and is the same as
the current repeater item ID then
// set the cssclass of the ItemTemplate's <litag
to "myCssClass"
}
}
I am not sure how I access the itemTemplate's tags?
Thanks in advance
JJ- Hide quoted text -

- Show quoted text -
Haven't tried it myself to varify that it works, but instead of usign
a runat="server" and having code behind, if the CSS class is coming
from a query string, why not try using some inline scripting on the
page, as shown:
<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li class="<%= Page.Request.QueryString["MyCssClass"] %>"><a
href=' '>Some Text Here</a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>

Apr 3 '07 #5
JJ
Thanks - both interesting approaches.

As the querystring isn't the _actual_ css class (the css class merely
changes depending on various caculations to do with the value of the
querystring) using the 'runat=server' method seems the more simpl approach
here.

I've never though of setting the css class with inline scripting as you
suggest though - I am sure it will be a useful method I will experment with
with other applications - thanks
"Evan M." <em*************@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
On Apr 3, 11:28 am, bruce barker <nos...@nospam.comwrote:
>add an id and runat=server on the <lithen you can use Item.FindControl
from the onitemdatbound event.

-- bruce (sqlwork.com)

JJ wrote:
I'm sure this is quite simple, but clearly not for me today:
How do you set the CSS Style of a tag in a repeater Item Template?
e.g. I have this repeater:
<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><a href=' '>Some Text Here</a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
...and I want to change the class of the '<li>' tag in the ItemTemplate
based on a query string setting:
protected void rpt_SubCategoryList_ItemCreated(Object Sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
//if current query string is x and is the same
as
the current repeater item ID then
// set the cssclass of the ItemTemplate's <li>
tag
to "myCssClass"
}
}
I am not sure how I access the itemTemplate's tags?
Thanks in advance
JJ- Hide quoted text -

- Show quoted text -

Haven't tried it myself to varify that it works, but instead of usign
a runat="server" and having code behind, if the CSS class is coming
from a query string, why not try using some inline scripting on the
page, as shown:
<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li class="<%= Page.Request.QueryString["MyCssClass"] %>"><a
href=' '>Some Text Here</a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>

Apr 5 '07 #6
JJ
Sorry - one more question:
What type would I cast the <licontrol to be able to set its css class?
JJ

"bruce barker" <no****@nospam.comwrote in message
news:e3**************@TK2MSFTNGP03.phx.gbl...
add an id and runat=server on the <lithen you can use Item.FindControl
from the onitemdatbound event.

-- bruce (sqlwork.com)

JJ wrote:
>I'm sure this is quite simple, but clearly not for me today:

How do you set the CSS Style of a tag in a repeater Item Template?

e.g. I have this repeater:

<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated" >
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><a href=' '>Some Text Here</a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
...and I want to change the class of the '<li>' tag in the ItemTemplate
based on a query string setting:
protected void rpt_SubCategoryList_ItemCreated(Object Sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
//if current query string is x and is the same as
the current repeater item ID then
// set the cssclass of the ItemTemplate's <li>
tag to "myCssClass"
}

}

I am not sure how I access the itemTemplate's tags?

Thanks in advance

JJ

Apr 5 '07 #7
On Apr 5, 5:56 am, "JJ" <a...@xyz.comwrote:
Sorry - one more question:
What type would I cast the <licontrol to be able to set its css class?
JJ

"bruce barker" <nos...@nospam.comwrote in message

news:e3**************@TK2MSFTNGP03.phx.gbl...
add an id and runat=server on the <lithen you can use Item.FindControl
from the onitemdatbound event.
-- bruce (sqlwork.com)
JJ wrote:
I'm sure this is quite simple, but clearly not for me today:
How do you set the CSS Style of a tag in a repeater Item Template?
e.g. I have this repeater:
<asp:Repeater runat="server" ID="rpt_SubCategoryList"
OnItemCreated="rpt_SubCategoryList_ItemCreated">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><a href=' '>Some Text Here</a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
...and I want to change the class of the '<li>' tag in the ItemTemplate
based on a query string setting:
protected void rpt_SubCategoryList_ItemCreated(Object Sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
//if current query string is x and is the same as
the current repeater item ID then
// set the cssclass of the ItemTemplate's <li>
tag to "myCssClass"
}
}
I am not sure how I access the itemTemplate's tags?
Thanks in advance
JJ- Hide quoted text -

- Show quoted text -
Since you just want access to the attributes collection, I'd use the
HtmlGenericControl class.

Evan M.

Apr 10 '07 #8

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

Similar topics

1
by: blugrasmaniac | last post by:
I have discovered that within a <ASP:REPEATER> control, I can specify multiple tags, such as <ItemTemplate> and <AlternatingItemTemplate>. So that I could write code like following: ...
0
by: ani | last post by:
Hi, I have a datalist control and within the Itemplate I have a radiobuttonlist control . I am binding data to the datalist control in Page_load . Also I have sqldatareader object that needs...
2
by: Jorge Ayala | last post by:
Well I'm trying to catch and act upon a button event that is placed within the item template of a repeater control. Yet the code I'm using isn't working. What I've seen out there to explain how...
3
by: Kevin Cunningham | last post by:
I have a repeater with some labels in it (code below). For whatever reason the text for the label is not persisted in viewstate on the postback. Is there a trick to get this to work? Is there...
4
by: jjack100 | last post by:
I have a DropDownList that is nested inside a Repeater. The datasource of the DropDownList is declared in the aspx, not the codebehind. So we have this: <asp:Repeater ID="rptOptions"...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
2
by: mj.redfox.mj | last post by:
Hi, I wonder if someone could possibly help with this? I have the following code, which is a nested repeater in turn nesting a datalist. This all works fine, together with my page-behind vb code...
1
by: mark4asp | last post by:
I have a table bound to a repeater. There is a DateTime column called EntryDate. When the EntryDate changes day I want to write the date out. I want to compare the value of an item from a table...
1
by: supraracer | last post by:
Can anyone show me an example of a solution to the problem described in this thread? How do I rebind a label in a repeater on a postback? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.