I have a page with 3-layers of menu: Main, Sub, and SubSub.
When a menu is clicked, the page will be redirected to something like ...somepage.aspx?mid=1&sid=2&ssid=3. Now the problem is: when a sub-sub menu is clicked, I need to change the 'CssClass' property of the LinkButton inside.(according to the query string 'ssid'). I write some code like this, but I fail to get the LinkButton inside the nested sub-sub menu datalist.
Here's the error msg:
System.NullReferenceException: Object reference not set to an instance of an object.
Line 142: btnSubSubMenuItem.CssClass = "StyleB";
[/color red]
Please help, thanks in advance.
When a menu is clicked, the page will be redirected to something like ...somepage.aspx?mid=1&sid=2&ssid=3. Now the problem is: when a sub-sub menu is clicked, I need to change the 'CssClass' property of the LinkButton inside.(according to the query string 'ssid'). I write some code like this, but I fail to get the LinkButton inside the nested sub-sub menu datalist.
Code:
void BindSubSubMenuList()
{
for(int i=0; i<datalistSubMenu.Items.Count; i++)
{
// bind every sub-sub menu list
}
// change the highlighted sub-sub menu's style
if(Request.QueryString["ssid"]!=null)
{
DataList subSubMenuList = datalistSubMenu.Items[subIndex].FindControl("datalistSubSubMenu") as DataList;
// !!!!!! This line causes the error !!!!!
LinkButton btnSubSubMenuItem = subSubMenuList.FindControl("btnSubSubMenuItem") as LinkButton;
//btnSubSubMenuItem.CssClass = "StyleB";
}
}
Code:
<asp:datalist id="datalistSubMenu" Runat="server" DataKeyField="Id">
<ItemTemplate>
<asp:LinkButton Runat=server ID="btnSubMenuItem" CommandName="select" Text='<%# DataBinder.Eval(Container, "DataItem.Label") %>' /><br>
<asp:DataList Runat="server" ID="datalistSubSubMenu" DataKeyField="Id" OnItemCommand="SubSubMenu_SelectionChanged">
<ItemTemplate>
<asp:LinkButton Runat="server" ID="btnSubSubMenuItem" CommandName="select" CssClass="StypleA">
<%# DataBinder.Eval(Container, "DataItem.Label") %>
</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:datalist>
Here's the error msg:
System.NullReferenceException: Object reference not set to an instance of an object.
Line 142: btnSubSubMenuItem.CssClass = "StyleB";
[/color red]
Please help, thanks in advance.