There are several problems with your code:
- You're trying to assign
e.Item.Value
to the variable i
; you should be using the equality operator instead. e.Item.Value
is a string
; you can't compare it to an int
with the equality operator.- You're setting the
ImageUrl
to a local path on your server's C:
drive. This won't work - it needs to be set to a URL on your site. Assuming the Images
folder is in the root of your site, use ~/Images/Your-Image-Here.ext
instead.
Also, since you're not using the loop variable (
i
) outside of the loop, you can declare it within the
for
block. And instead of using
i <= Count - 1
, it's more common to use
i < Count
.
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
int itemValue = int.Parse(e.Item.Value);
MultiView1.ActiveViewIndex = itemValue;
for (int i = 0; i < Menu1.Items.Count; i++)
{
if (i == itemValue)
{
Menu1.Items[i].ImageUrl = "~/Images/selectedtab.GIF";
}
else
{
Menu1.Items[i].ImageUrl = "~/Images/unselectedtab.gif";
}
}
}