DataList column alignment?

G

Guest

I'm using DataList to present tabular data but am often having problems with
some rows column alignment being out of synch with the rest of the rows.

My DataList looks similar to this...:

<asp:datalist id="DataList1" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="400">
<tr>
<td width="100">First Name</td>
<td width="100">Surname</td>
<td width="100">DOB</td>
<td width="100">Gender</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td width="100"><%# DataBinder.Eval(Container.DataItem,
"firstname") %></td>
<td width="100"><%# DataBinder.Eval(Container.DataItem,
"surname") %></td>
<td width="100"><%# DataBinder.Eval(Container.DataItem, "dob")
%></td>
<td width="100"><%# DataBinder.Eval(Container.DataItem,
"gender") %></td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>

....but if any data exceeds the maximum width of it's column, that particular
"cell" is getting expanded to accomodate the data. I think the problem lies
in using tables in the <ItemStyle> tags, so for each row, the table is
automatically altered to accomodate the data it hold. Of course, this makes
the final output look unprofessional.

Is there any way round this?

Thanks
Ben
 
G

Guest

Hi Eliyahu

I tried this and it didn't work for me. I'll have another go though. Have
you used it yourself?

When I put <tr> etc tag between <ItemTemplate> tags (withou an accompayning
<table> tag), the IDE says that <tr> tags can't be used in this context

Ben
 
G

Guest

There's no particular reason I'm using a DataList other than that's what I've
always used. I'll give Repeater a go.

Thanks

Ben

Does repeater use the same templates
 
E

Eliyahu Goldin

Ben,

Basically, you need to put everything in the same table:

<table border="0" cellpadding="0" cellspacing="0" width="400">
<colgroup span="4" width="100" />
<asp:datalist id="DataList1" runat="server">
<HeaderTemplate>
<tr>
<td>First Name</td>
<td>Surname</td>
<td>DOB</td>
<td>Gender</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "firstname")
%></td>
<td><%# DataBinder.Eval(Container.DataItem, "surname")
%></td>
<td><%# DataBinder.Eval(Container.DataItem, "dob") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "gender")
%></td>
</tr>
</ItemTemplate>
</asp:datalist>
</table>

Eliyahu
 
E

Eliyahu Goldin

I use this with a repeater. A datalist may create it's own tables, that's
why it won't like yours. Do you have a particular reason for using a
datalist rather than a repeater?

One thing is absolutely clear. There is no way of aligning columns other
than putting them in the same table.

Eliyahu
 
I

intrader

I'm using DataList to present tabular data but am often having problems with
some rows column alignment being out of synch with the rest of the rows.

My DataList looks similar to this...:

<asp:datalist id="DataList1" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="400">
<tr>
<td width="100">First Name</td>
<td width="100">Surname</td>
<td width="100">DOB</td>
<td width="100">Gender</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td width="100"><%# DataBinder.Eval(Container.DataItem,
"firstname") %></td>
<td width="100"><%# DataBinder.Eval(Container.DataItem,
"surname") %></td>
<td width="100"><%# DataBinder.Eval(Container.DataItem, "dob")
%></td>
<td width="100"><%# DataBinder.Eval(Container.DataItem,
"gender") %></td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>

...but if any data exceeds the maximum width of it's column, that particular
"cell" is getting expanded to accomodate the data. I think the problem lies
in using tables in the <ItemStyle> tags, so for each row, the table is
automatically altered to accomodate the data it hold. Of course, this makes
the final output look unprofessional.

Is there any way round this?

Thanks
Ben
The Header should have the table but not the table end. There should not
be a table in the ItemTemplate (unless it is for another purpose)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top