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

Complex DataList formatting with a <table>

Hi,

I am working on an app right now that makes extensive use of the DataList
control. I chose the DataList because I need to do multi row formatting. I
am using it like so.

<DataList id="test" runat="server>

<HeaderTemplate>

<table>

<tr>

<td>

First Name

</td>

<td>

Last Name

</td>

</tr>

<tr>

<td colspan=2>

Address

</td>

</tr>

</HeaderTemplate>

<ItemTemplate>

<tr>

<td>

DataBinder.Eval code..

</td>

<td>

DataBinder.Eval code..

</td>

</tr>

<tr>

<td colspan=2>

DataBinder.Eval code..

</td>

</tr>

</ItemTemplate>

<FooterTemplate>

</table>

</FooterTemplate>

</DataList>

For simplicities sake I left out quite a few controls. Because I am
overlapping the <table> tags with the Item Template, Footer Template, and
Header Template, the <SelectedItemStyle> formatting isn't working after I
select one of the rows. If I make the <ItemTemplate> have a nested
<table></table> tag without overlapping the Header, Item, and Footer
Templates, the <SelectedItemStyle> works fine. However, I am doing it this
way because I need the table rows to line up between the header and items.

I found a way to work around the SelectedItemStyle problem. I capture the
ItemCommand event of the DataList, and I use the following code to highlight
the selected item.

foreach(Control ctrl in e.item.controls)

{

if(ctrl is LiteralControl)

{

((LiteralControl)ctrl).Text =
((LiteralControl)ctrl).Text.Replace("<tr>", "<tr bgcolor=\"Gold\"");

}

}

It works for the most part, however, when I select another element on the
page that causes a postback, the SelectedItem looses its highlighting as the
page re-draws.

Any ideas?
Nov 17 '05 #1
2 5215
One thing I have found in my reading is that the order of
your templates is important. I don't remember the exact
order but I do remember that the header template comes
first followed by the footer template and then any other
templates you want to set up.
-----Original Message-----
Hi,

I am working on an app right now that makes extensive use of the DataListcontrol. I chose the DataList because I need to do multi row formatting. Iam using it like so.

<DataList id="test" runat="server>

<HeaderTemplate>

<table>

<tr>

<td>

First Name

</td>

<td>

Last Name

</td>

</tr>

<tr>

<td colspan=2>

Address

</td>

</tr>

</HeaderTemplate>

<ItemTemplate>

<tr>

<td>

DataBinder.Eval code..

</td>

<td>

DataBinder.Eval code..

</td>

</tr>

<tr>

<td colspan=2>

DataBinder.Eval code..

</td>

</tr>

</ItemTemplate>

<FooterTemplate>

</table>

</FooterTemplate>

</DataList>

For simplicities sake I left out quite a few controls. Because I amoverlapping the <table> tags with the Item Template, Footer Template, andHeader Template, the <SelectedItemStyle> formatting isn't working after Iselect one of the rows. If I make the <ItemTemplate> have a nested<table></table> tag without overlapping the Header, Item, and FooterTemplates, the <SelectedItemStyle> works fine. However, I am doing it thisway because I need the table rows to line up between the header and items.
I found a way to work around the SelectedItemStyle problem. I capture theItemCommand event of the DataList, and I use the following code to highlightthe selected item.

foreach(Control ctrl in e.item.controls)

{

if(ctrl is LiteralControl)

{

((LiteralControl)ctrl).Text =
((LiteralControl)ctrl).Text.Replace("<tr>", "<tr bgcolor=\"Gold\"");
}

}

It works for the most part, however, when I select another element on thepage that causes a postback, the SelectedItem looses its highlighting as thepage re-draws.

Any ideas?
.

Nov 17 '05 #2
Hi Leo,

I think you may consider adding the style to <tr> tag in the SelectedItem
template. For example:
<SelectedItemTemplate >
<tr bgcolor=Yellow>
<td></td>
<td>
<asp:Label id="ItemLabel" Text='<%# DataBinder.Eval(Container.DataItem,
"Item") %>' runat="server"/>
</td>
<td>
<asp:Label id="QtyLabel" Text='<%# DataBinder.Eval(Container.DataItem,
"Qty") %>' runat="server"/>
</td>
<td>
<asp:Label id="PriceLabel" Text='<%# DataBinder.Eval(Container.DataItem,
"Price", "{0:c}") %>' runat="server"/>
</td>
</tr>
</SelectedItemTemplate>

This also can make the selected Item has yellow backgroud

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 17 '05 #3

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

Similar topics

1
by: Philo | last post by:
How do I select all <div> tags except those which contain a <table> tag somewhere within them? Example XML: <********************** sample input ***********************> <txtSectionBody>...
8
by: bearclaws | last post by:
I am looping through a list of categories and want to display the list horizontally (instead of vertically). I want to create a single row with 4 list items in each cell of the row. I thought...
3
by: Paul Thompson | last post by:
When I put a <div ...> inside a <table> specification, functionality is not there. When I put the <table> inside the <div> everything works. Why is that?
61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
10
by: BuddhaBuddy | last post by:
Platform is DB2/NT 7.2.9 The table was created like this: CREATE TABLE MYTEST ( MYTESTOID bigint not null primary key, FK_OTHEROID bigint not null references other, FK_ANOTHEROID bigint not...
0
by: timnels | last post by:
I've got a bizzare issue where I have an XML file to load into a data set like: <conversion> <table name="parent"> <table name="child"> </table> </table> <table name="another parent"> ....
1
by: prefersgolfing | last post by:
I'm not using Master Pages, yet I'd like to display the contents of an HTML page within a <table><tr><td> on a .aspx. I have a lengthy guide already paginated in html. I'd like to embed the...
3
by: PYG | last post by:
Hi everybody I have a simple question : If i use this code : <body style="font-size:24px;color:blue;"> Text in body <table> <tr><td> Text in table
0
by: =?Utf-8?B?R3JlZw==?= | last post by:
I've created my table and alli is fine. I name my <tdtags to make them easier to identify when my table gets large. Anyway, I am naming as such: <td id="cellName" > Now, sometimes when make a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.