Question

I am using code like the following to operate on every row in my table after it is bound:

    protected void dtlImages_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item)
        {
            LinkButton button = (LinkButton)e.Item.FindControl("lbDeleteImage");
            button.Visible = false;
        }
    }

I have a button next to each image in the table that allows me to delete the image (row). The seems to work well but what actually happens is that it makes every other row's item (delete button) invisible. What can cause that to happen? This is difficult to find the correct words to search for in Google. :)

If you saw my table it would look like a nice list of images with a description, and image and every other row having a delete button next to the image. In this simple example (I have omitted the conditionals for clarity) they should all be gone I would think.

Any suggestions?

Was it helpful?

Solution

I think it's very possible that you need to check for ListItemType.AlternatingItem as well, like this:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

Especially considering the fact that it's only catching every other row.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top