Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
ASP.NET
<div>
        <table>
            <tr>
                <td>
                    <asp:Menu ID="Menu1" Width="168px" runat="server" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False"
                        OnMenuItemClick="Menu1_MenuItemClick">
                        <Items>
                            <asp:MenuItem ImageUrl="~/Images/selectedtab.GIF" Text=" " Value="0"></asp:MenuItem>
                            <asp:MenuItem ImageUrl="~/Images/unselectedtab.GIF" Text=" " Value="1"></asp:MenuItem>
                            <asp:MenuItem ImageUrl="~/Images/unselectedtab.GIF" Text=" " Value="2"></asp:MenuItem>
                        </Items>
                    </asp:Menu>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                        <asp:View ID="Tab1" runat="server">
                            <table style="width: 600px; height: 300px" cellpadding="0" cellspacing="0">
                                <tr valign="top">
                                    <td class="TabArea" style="width: 600px">
                                        <br />
                                        <br />
                                        TAB VIEW 1 INSERT YOUR CONENT IN HERE CHANGE SELECTED IMAGE URL AS NECESSARY
                                    </td>
                                </tr>
                            </table>
                        </asp:View>
                        <asp:View ID="Tab2" runat="server">
                            <table style="width: 600px; height: 300px" cellpadding="0" cellspacing="0">
                                <tr valign="top">
                                    <td class="TabArea" style="width: 600px">
                                        <br />
                                        <br />
                                        TAB VIEW 2 INSERT YOUR CONENT IN HERE CHANGE SELECTED IMAGE URL AS NECESSARY
                                    </td>
                                </tr>
                            </table>
                        </asp:View>
                        <asp:View ID="Tab3" runat="server">
                            <table cellpadding="0" cellspacing="0" style="width: 600px; height: 300px">
                                <tr valign="top">
                                    <td class="TabArea" style="width: 600px">
                                        <br />
                                        <br />
                                        TAB VIEW 3 INSERT YOUR CONENT IN HERE CHANGE SELECTED IMAGE URL AS NECESSARY
                                    </td>
                                </tr>
                            </table>
                        </asp:View>
                    </asp:MultiView>
                </td>
            </tr>
        </table>
    </div>


C#
#region Menu1_MenuItemClick
        protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            MultiView1.ActiveViewIndex = Int32.Parse(e.Item.Value);
            int i = 0;
            //Make the selected menu item reflect the correct imageurl
            for (i = 0; i <= Menu1.Items.Count - 1; i++)
            {
                if (i = e.Item.Value)
                {
                    Menu1.Items[i].ImageUrl = "C:/Users/1502/Desktop/MOLFrameWork/MOLFrameWork/MOLFrameWork/Images/selectedtab.GIF";
                }
                else
                {
                    Menu1.Items[i].ImageUrl = "C:/Users/1502/Desktop/MOLFrameWork/MOLFrameWork/MOLFrameWork/Images/unselectedtab.gif";
                }
            }
        }
        #endregion
Posted

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.


C#
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";
        }
    }
}
 
Share this answer
 
You are using an assignment operation which obviusly give error in if condition expresson

use relational operator
i.e ==
put

if (i == e.Item.Value)
{
//Your logic;
}



and Make sure e.Item.Value returns an integer value
 
Share this answer
 
v2
Comments
Member 10534998 30-May-14 7:24am    
i wrote ==, bt evn shwng error operator cant be applied to operands of type int and string"
Its a common parsing error
The value which you are trying to cast is not in a number format you will get this exception.
instead of int.Parse try int.TryParse

C#
int result = 0;
           int.TryParse("", out result);
            MultiView1.ActiveViewIndex = result;


but try to figure out why the e.Item.Value is not getting in a valid number format. unless u fix this, you issue will not be resolved.
 
Share this answer
 
Comments
Member 10534998 30-May-14 7:12am    
error iz in the line- if (i = e.Item.Value), itz saying tht cant implicitly convert string to int.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900