problem with datalist and server tags

G

Guest

I hope someone can help with this, because it’s driving me crazy. It’s also
a little tough to describe what’s happening, but I’ll do my best.

I have a class that takes a ProductID and then uses it to generate some
html. I then insert that HTML into my page via server tags. I’m using a
datalist for the content, making a 3 x 3 grid.

For each instance of my ItemTemplate, I’m changing a pic, some text, a link
button, and my class-generated html. The first three change for each new
ProductID. However, the stuff between the server tags appears to be running
only after the entire page is rendered, meaning that my class is called nine
times with the same ProductID.

I’ve included below the code that I think must contain the problem. The
class does it’s job fine. The ProductID is also changing in
list_ItemDataBound(). I can post the class too if it’ll be helpful, but this
post is already getting long.

Thanks for any help.

-Josh Nikle


// Snip from my aspx page
…<asp:LinkButton ID="addToCartButton" runat="server" Text="Buy now!"
CommandArgument='<%# Eval("ProductID") %>'></asp:LinkButton> | <a
href='Product.aspx?ProductID= <%# Eval("ProductID")
%>'>Info</a></font></strong>
</td>
</tr>
<tr height=14 width="100%">
<td align="center" valign="middle" colspan=2 class="SectionHeader">
<%
prodID = productID;
catBrowse = new BrowseCategory(prodID);
Response.Write(catBrowse.browseCategoryHTML());
%>
</td>
</tr>…


// My variable list at the top of the aspx.cs file
protected BrowseCategory catBrowse;
protected int prodID;
protected int productID;


// Gets the ProductID to pass to the BrowseCategory class
protected void list_ItemDataBound(object sender, DataListItemEventArgs e)
{
productID = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem,
"ProductID"));

}
 
M

Muhammad Naveed Yaseen

<%
prodID = productID;
catBrowse = new BrowseCategory(prodID);
Response.Write(catBrowse.browseCategoryHTML());
%>

<% %> blocks have different timing of *execution* than timing(s) of <
%# %> *evaluation*.

Replace this <% %> block with following line (code behind not needed)

<asp:Literal runat="server" ID="Literal1" EnableViewState="false"
Text='<%# new
BrowseCategory(Convert.ToInt32(Eval("ProductID"))).browseCategoryHTML()
%>' />
 
G

Guest

works perfectly! thanks. this was making me crazy. thanks too for the
extra info on execution and evaluation.

-josh
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top