467,877 Members | 1,135 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

DataList column alignment?

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
Nov 19 '05 #1
  • viewed: 3475
Share:
5 Replies
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

"Ben Fidge" <Be******@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
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

Nov 19 '05 #2
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

"Eliyahu Goldin" wrote:
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

"Ben Fidge" <Be******@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
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


Nov 19 '05 #3
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

"Ben Fidge" <Be******@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com...
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

"Eliyahu Goldin" wrote:
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

"Ben Fidge" <Be******@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
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


Nov 19 '05 #4
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
"Eliyahu Goldin" wrote:
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

"Ben Fidge" <Be******@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com...
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

"Eliyahu Goldin" wrote:
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

"Ben Fidge" <Be******@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
> 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


Nov 19 '05 #5
On Wed, 22 Jun 2005 06:34:03 -0700, Ben Fidge wrote:
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)

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by TCORDON | last post: by
1 post views Thread by Rachel Devons | last post: by
3 posts views Thread by Danny Tuppeny | last post: by
reply views Thread by TCORDON | last post: by
5 posts views Thread by Vikas Kumar | last post: by
4 posts views Thread by rn5a | last post: by
1 post views Thread by Brock | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.