Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get a LinkButton inside a nested DataList?

Status
Not open for further replies.

coospaa

Programmer
May 1, 2003
33
SG
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.

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.
 
oops... solved already. I forgot to get the 'item[index]' of the nested datalist.

Sorry and thanks to all who have already read this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top