views:

12

answers:

0

Hi guys.

On a masterpage I have ASP Menu control.

It looks like this:

        <asp:Menu ID="mnuMainMenu" runat="server"  
            DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="Medium" 
            ForeColor="#7C6F57"  
            Orientation="Horizontal" StaticSubMenuIndent="10px" Font-Bold="True" 
                Font-Italic="False" onprerender="mnuMainMenu_PreRender">
            <Items>
                <asp:MenuItem Text="Projekty" Value="Projekty" NavigateUrl="~/Projekty.aspx"></asp:MenuItem>
                <asp:MenuItem Text="Licencje"></asp:MenuItem>
                <asp:MenuItem Text="Kontrahenci" Value="Kontrahenci"></asp:MenuItem>
                <asp:MenuItem Text="Pomoc" Value="Pomoc" NavigateUrl="~/Pomoc.aspx"></asp:MenuItem>
            </Items>
        </asp:Menu>

This is a static part of the menu. However, under a "Licencje" node I am generating dynamicaly child nodes on each page request.

This is the code:

protected void mnuMainMenu_PreRender(object sender, EventArgs e)
{
  MenuItem muiLicencje = mnuMainMenu.FindItem("Licencje");
  if (muiLicencje != null)
    muiLicencje.ChildItems.Clear();
  IDataReader Licencje = (IDataReader)dsMenuLicencjeItems.Select(DataSourceSelectArguments.Empty);
  try
  {
    while (Licencje.Read())
    {
      MenuItem muiLicencja = new MenuItem(Licencje["Pro_Kod"].ToString());
      muiLicencja.NavigateUrl = "Licencje.aspx?ID=" + Licencje["Pro_ProID"].ToString();
      muiLicencje.ChildItems.Add(muiLicencja);
    }
  }
  finally
  {
    Licencje.Close();
  }      
}

The content of the "Licencje" node is changing dynamicaly and as you see, firstly I need to clear any previously created ChildNodes (to prevent duplicates).

The problem is that not each created ChildItems allow me to click on it after rendering. When I hoover the mouse over the given menu item, sometimes I see in my browser a url to new page(then I can click on menu item) and sometimes it is not there. The link is visible in the bottom panel of my browser.

I've checked my data source, I've debugged ChildItems collection and all items are fine, each item has its own NavigateUrl property.

The curious thing is that menu items which are clickable are set up randomly. Sometimes I can click 1st, 2nd, 6th item in menu, sometimes those are different items. I mean, which each refresh those can be a different set of clickable items.

I am lost here. Any ideas?

I've also try to use itemclick event but the behaviour is the same. On som eitem event is fired, on other it is not.

As requested, here is the definition of DataSource:

    <asp:SqlDataSource ID="dsMenuLicencjeItems" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SELConnectionString %>" 
        SelectCommand="SELECT Pro_ProID Pro_Kod Pro_Nazwa FROM dbo.Projekty ORDER BY Pro_Kod" 
        DataSourceMode="DataReader">
    </asp:SqlDataSource>