Konstantinos Pantos said:
Can you post more code? e.g the whole repeater control and not just the
ItemTemplate part?
Sure, but I should point out that when I copied the code into another
file to create a full page that showed the problem, it worked fine!!
This sounds like there's some weird problem with the whole page, not
just this code. I'm not sure why though.
Anyway, here's the repeater itself...
<asp:Repeater ID="rptProducts" RunAt="Server" OnItemDataBound="rptProducts_OnItemDataBound">
<HeaderTemplate><table border="0" cellpadding="2" cellspacing="0" width="100%"></HeaderTemplate>
<ItemTemplate><tr><td align="left" valign="top" class="altTableCell"><small><asp:CheckBox ID="chkDelete" Text="" RunAt="server"/> <asp:Imag
e ID="imgStatus" runat="server" Width="10" Height="10" /> <asp:HyperLink ID="hlkProduct" NavigateUrl='<%# "product.aspx?productid=" +
DataBinder.Eval(Container.DataItem, "productid") %>' Text='<%#DataBinder.Eval(Container.DataItem, "PName")%>' RunAt="server" /></small></td></t
r></ItemTemplate>
<AlternatingItemTemplate><tr><td align="left" valign="top" class="tableCell"><small><asp:CheckBox ID="chkDelete" Text="" RunAt="server"/> <a
sp:Image ID="imgStatus" runat="server" Width="10" Height="10" /> <asp:HyperLink ID="hlkProduct" NavigateUrl='<%# "product.aspx?productid="
+ DataBinder.Eval(Container.DataItem, "productid") %>' Text='<%#DataBinder.Eval(Container.DataItem, "PName")%>' RunAt="server" /></small></td>
</tr></AlternatingItemTemplate>
<FooterTemplate></table><small>Products marked <img src="images/product-blank.gif" alt="" /> are visible and not on special offer.<br />Products
marked <img src="images/product-special-offer.gif" alt="" /> have at least one price on special offer.<br />Products marked <img src="images/product-
not-visible.gif" alt="" /> are not visible on the web site.</small><br /></FooterTemplate>
</asp:Repeater>
The code-behind contains the following code for the OnItemDataBound
event for the repeater. Note that all this does is set the image to be
shown, depending on the status of the product. I'm certain this bit is
irrelevant to the problem...
protected void rptProducts_OnItemDataBound(object source, RepeaterItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
// set the image depending on the product's status
Image imgStatus = (Image)e.Item.FindControl("imgStatus");
if (DataBinder.Eval(e.Item.DataItem, "Show_product").ToString() == "n") {
imgStatus.ImageUrl = "/images/product-not-visible.gif";
imgStatus.AlternateText = "Product is not visible";
} else if (Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "n")) > 0) {
imgStatus.ImageUrl = "/images/product-special-offer.gif";
imgStatus.AlternateText = "Product is visible and on special offer";
} else {
imgStatus.ImageUrl = "/images/product-blank.gif";
imgStatus.AlternateText = "Product is visible and not on special offer";
}
}
}
....and the following code for the button that is supposed to collect the
names of the products to delete...
public void btnDeleteProducts_Click(object o, EventArgs e) {
for (int i=0; i<rptProducts.Items.Count; i++) {
//litMsg.Text += "<br>(" + i.ToString() + ") Checking... (" + (((CheckBox)rptProducts.Items
.FindControl("chkDelete")).Checked).ToString() + ") ";
if (((CheckBox)rptProducts.Items.FindControl("chkDelete")).Checked) {
//litMsg.Text += " and deleting... ";
// get the URL of the target page
string strNavUrl = ((HyperLink)rptProducts.Items.FindControl("hlkProduct")).NavigateUrl;
// extract the product ID
int productID = Convert.ToInt32(strNavUrl.Substring(strNavUrl.IndexOf("=")+1));
// get the name of the product
string strNavText = ((HyperLink)rptProducts.Items.FindControl("hlkProduct")).Text;
litMsg.Text += "Deleted " + strNavText + "<br>";
BindRepeater(Convert.ToInt32(litCatId.Text), litCatName.Text);
}
}
}
Note that this code just lists the names (pulled from the Hyperlink's
Text property), it doesn't delete them from the database yet. litMsg is
a Literal control on the page, used for me to see what's going on.
If you can see what's wrong here I would be very grateful. Thanks.