Monday, March 26, 2012

TreeView PopulateOnDemand within AccordionPane

I have an accordion inside of an Accordion Panel, which is generated from a database. I have the treeview set to populate on demand if there are any subnodes, using the TreeNodePopulate event of the TreeView. Since the Tree is inside of the Accordion Pane, I lose design support, and have to explicitly find and cast the control from the Accordion object. Becuase of this, I lose the event handling binding to that Treeview node. I'm not sure If explicitly fetching and casting is right to begin with, so I'd rather not waste a lot of time trying to manually wire the events to the casted TreeView in codebehind if there is a better way.

Expand Category 1

The target 'ctl00$ContentPlaceHolder2$ctl01$TreeView1' for the callback could not be found or did not implement ICallbackEventHandler.

<atlastoolkit:AccordionPane ID="AccordionPane2" runat="server">
<Header>
<a href="http://links.10026.com/?link=" onclick="return false;" class="accordionLink">Panel 2</a></Header>
<Content>
<asp:TreeView ID="TreeView1" ExpandDepth="0" PopulateNodesFromClient="true" ShowLines="true"
ShowExpandCollapse="true" runat="server" OnTreeNodePopulate="TreeView1_TreeNodePopulate" />
</Content>
</atlastoolkit:AccordionPane>

TreeView tree1;

protected void Page_Load(object sender, EventArgs e)
{
tree1 = (TreeView)AccordionPane2.ContentContainer.FindControl("TreeView1");

}

protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
PopulateSubLevel(Convert.ToInt32(e.Node.Value), e.Node);
}

private void PopulateSubLevel(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection(@dotnet.itags.org."server=SYSSIMERT01\SQLEXPRESS;Trusted_Connection=true;DATABASE=TreeViewSampleDB");
SqlCommand objCommand = new SqlCommand("select id,title,(select count(*) FROM SampleCategories WHERE parentid=sc.id) childnodecount FROM SampleCategories sc where parentID=@dotnet.itags.org.parentID", objConn);

objCommand.Parameters.Add("@dotnet.itags.org.parentID", SqlDbType.Int).Value = parentid;

SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, parentNode.ChildNodes);
}

Hi j05h,

It sounds like the event isn't being properly wired up whenever you postback. If you're creating controls dynamically (and then also their event handlers), be sure to recreate them on postback. If this doesn't help, perhaps you can provide asmall sample demonstrating the problem that I can run.

Thanks,
Ted

No comments:

Post a Comment