468,121 Members | 1,429 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,121 developers. It's quick & easy.

DataList - accessing <tr>

I have a data list control with 3 columns. I want every second *row* to
have a dfferent CSS class. Can someone tell me how to access the parent
tablerow, and add a cssclass? I'm guessing I'll need to put some code in
the itemcreated or itemdatabound?

Thanks in advance,

Duncan

---/ snip /---

<asp:datalist id="dlRegionList" runat="server" repeatcolumns=3
cssclass="tbl" width="100%">
<itemtemplate>
<a href="search.asp?area=<%# DataBinder.Eval(Container.DataItem,
"Regions_ID") %>">
<%# DataBinder.Eval(Container.DataItem, "RegionName") %>
</a>
</itemtemplate>

<alternatingitemtemplate>
<!-- this needs to have: tr class="tbl_2row" -->
<a href="search.asp?area=<%# DataBinder.Eval(Container.DataItem,
"Regions_ID") %">
<%# DataBinder.Eval(Container.DataItem, "RegionName") %>
</a>
</alternatingitemtemplate>
</asp:datalist>

Nov 17 '05 #1
3 3494
Define an ItemTemplate and an AlternateItemTemplate. This allows you to have
every other item with a different format.

"Dunc" <du**@ntpcl.f9.co.uk> wrote in message
news:eC****************@TK2MSFTNGP09.phx.gbl...
I have a data list control with 3 columns. I want every second *row* to
have a dfferent CSS class. Can someone tell me how to access the parent
tablerow, and add a cssclass? I'm guessing I'll need to put some code in
the itemcreated or itemdatabound?

Thanks in advance,

Duncan

---/ snip /---

<asp:datalist id="dlRegionList" runat="server" repeatcolumns=3
cssclass="tbl" width="100%">
<itemtemplate>
<a href="search.asp?area=<%# DataBinder.Eval(Container.DataItem,
"Regions_ID") %>">
<%# DataBinder.Eval(Container.DataItem, "RegionName") %>
</a>
</itemtemplate>

<alternatingitemtemplate>
<!-- this needs to have: tr class="tbl_2row" -->
<a href="search.asp?area=<%# DataBinder.Eval(Container.DataItem,
"Regions_ID") %">
<%# DataBinder.Eval(Container.DataItem, "RegionName") %>
</a>
</alternatingitemtemplate>
</asp:datalist>

Nov 17 '05 #2
Marina,

Thanks for your reply. At the bottom of the post, I'd included the code -
including an itemtemplate and alternateitemtemplate; this doesn't work, as
we're effectively trying to style the whole parent row, not a single item.

Any thoughts?

D

"Marina" <so*****@nospam.com> wrote in message
news:O0****************@TK2MSFTNGP15.phx.gbl...
Define an ItemTemplate and an AlternateItemTemplate. This allows you to
have every other item with a different format.

"Dunc" <du**@ntpcl.f9.co.uk> wrote in message
news:eC****************@TK2MSFTNGP09.phx.gbl...
I have a data list control with 3 columns. I want every second *row* to
have a dfferent CSS class. Can someone tell me how to access the parent
tablerow, and add a cssclass? I'm guessing I'll need to put some code in
the itemcreated or itemdatabound?

Thanks in advance,

Duncan

---/ snip /---

<asp:datalist id="dlRegionList" runat="server" repeatcolumns=3
cssclass="tbl" width="100%">
<itemtemplate>
<a href="search.asp?area=<%# DataBinder.Eval(Container.DataItem,
"Regions_ID") %>">
<%# DataBinder.Eval(Container.DataItem, "RegionName") %>
</a>
</itemtemplate>

<alternatingitemtemplate>
<!-- this needs to have: tr class="tbl_2row" -->
<a href="search.asp?area=<%# DataBinder.Eval(Container.DataItem,
"Regions_ID") %">
<%# DataBinder.Eval(Container.DataItem, "RegionName") %>
</a>
</alternatingitemtemplate>
</asp:datalist>


Nov 17 '05 #3
Try putting everything in each template into a div, with the appropriate
css class.
"Dunc" <du**@ntpcl.f9.co.uk> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Marina,

Thanks for your reply. At the bottom of the post, I'd included the code -
including an itemtemplate and alternateitemtemplate; this doesn't work, as
we're effectively trying to style the whole parent row, not a single item.

Any thoughts?

D

"Marina" <so*****@nospam.com> wrote in message
news:O0****************@TK2MSFTNGP15.phx.gbl...
Define an ItemTemplate and an AlternateItemTemplate. This allows you to
have every other item with a different format.

"Dunc" <du**@ntpcl.f9.co.uk> wrote in message
news:eC****************@TK2MSFTNGP09.phx.gbl...
I have a data list control with 3 columns. I want every second *row* to
have a dfferent CSS class. Can someone tell me how to access the parent
tablerow, and add a cssclass? I'm guessing I'll need to put some code in
the itemcreated or itemdatabound?

Thanks in advance,

Duncan

---/ snip /---

<asp:datalist id="dlRegionList" runat="server" repeatcolumns=3
cssclass="tbl" width="100%">
<itemtemplate>
<a href="search.asp?area=<%# DataBinder.Eval(Container.DataItem,
"Regions_ID") %>">
<%# DataBinder.Eval(Container.DataItem, "RegionName") %>
</a>
</itemtemplate>

<alternatingitemtemplate>
<!-- this needs to have: tr class="tbl_2row" -->
<a href="search.asp?area=<%# DataBinder.Eval(Container.DataItem,
"Regions_ID") %">
<%# DataBinder.Eval(Container.DataItem, "RegionName") %>
</a>
</alternatingitemtemplate>
</asp:datalist>



Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Geddes | last post: by
4 posts views Thread by El Diablo | last post: by
3 posts views Thread by Christopher Benson-Manica | last post: by
1 post views Thread by prefersgolfing | last post: by
3 posts views Thread by jack | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.