Datalist array binding issues

G

Guest

Thanks in advance to anyone who can help :)

I have my datalist bound to a normal, single dimension string array (with
three elements) as its data source. In the scripting for the datagrid, I have
it creating a table element in the <HeaderTemplate> and creating a row in the
<ItemTemplate> section. The <FooterTemplate> only has a closing </table> tag
within it.

The problem:
The datagrid is repeating all of the elements in the array as rows in run
time. (i.e., the datalist is repeating the same elements in THREE rows). The
# of times it repeats is dependent on the number of items in the array (i.e.
two elements in the array, and the datalist will repeat the row two times)

Here's the script:
<asp:DataList ID="dlTest" runat="server"><HeaderTemplate><table><tr
style='color:#FFFFFF; background-color:#0000cc'><th>Name</th><th>Phone
Number</th><th>Title</th></tr></HeaderTemplate>
<ItemTemplate><tr><td><%#this.stuff[0]
%></td><td><%#this.stuff[1]
%></td><td><%#this.stuff[2]%></td></tr></ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:DataList>

Where [stuff] is the name of the string array.
Anyone?
 
E

Eliyahu Goldin

You ItemTemplate databinds to the same first 3 array items. According to
this, if the array has 10 items, you will get 10 rows with the same 3 first
items. Is it what you are getting? It is not clear what exactly you are
trying to achieve. Do you want to have three items in each row?
 

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