vb.net - Event handler to use when nodes of ASP.Net TreeView are clicked by user -



vb.net - Event handler to use when nodes of ASP.Net TreeView are clicked by user -

using next web.sitemap example, create event handler grab when user clicks on "teachers" link of asp.net treeview. happens parent node.

<sitemapnode title="teachers" url="~/defaultteachers.aspx" > <sitemapnode url="~/teachers.aspx" title="teachers" description="maintain details of each teacher." /> <sitemapnode url="~/teacherschedules.aspx" title="teacher schedules" description="maintain teacher schedules." /> <sitemapnode url="~/teacheremailnotices.aspx" title="email notices teachers" description="email notices teachers." /> </sitemapnode>

can tell me event place in markup of asp.net treeview maybe this?

<asp:treeview id="treeviewmain" runat="server" expanddepth="0" onuserclickedthelink="treeviewmain_userclickedthelink" datasourceid="knowledgeacademysitemap"> <rootnodestyle imageurl="/images/book.png" /> <parentnodestyle imageurl="/images/book.png" /> <leafnodestyle imageurl="/images/book.png" /> </asp:treeview>

also in code-behind file place e.node or in "if" statement test node clicked:

if e.node.text = "teachers" ' close other nodes , open 3 leaf nodes under "teachers" here. '---------------------------------------------------------------------------------- end if

the problem treeview can perform 1 of 2 functions, are:

post back navigate

since you're setting tree view info source site map perform navigate function , not fire post event. - oh cliked on teachers node i'm going take teachers page , nil more.

there's number of things can try:

handle processing within load event of teachers page. when event fires means teachers page beingness loaded @ point can write code expand , collapse tree view items. another alternative rid of sitemap , utilize xmldatasource maps custom xml file, way tree view have post back behavior , able check every clicked node in onselectednodechanged event:

sample xml file:

<menu name="menu"> <teachers name="teachers"> <teacher name="teacher1" /> <teacher name="teacher2" /> <teacher name="teacher3" /> </teachers> </menu>

code behind:

protected sub page_load(byval sender object, byval e system.eventargs) handles me.load if not page.ispostback dim ds xmldatasource = new xmldatasource ds.datafile = server.mappath("~/app_data/menu.xml") treeviewmain.datasource = ds treeviewmain.databind() end if end sub protected sub selectionchanged(sender object, e eventargs) handles treeviewmain.selectednodechanged dim selected string = treeviewmain.selectedvalue if selected.equals("teachers") 'do required processing , manually redirect teachers page end if end sub

the problem approach of course of study you'll need check every clicked item , manually redirect user particular page won't acceptable if have many tree view items evaluate

asp.net vb.net treeview nodes

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -