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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically populate tree view

Status
Not open for further replies.

newbie14

Technical User
Feb 14, 2009
81
MY
Dear All,
I am trying to populate dynamically my treeview but unfortunately when I run the code below nothing comes out and I have check my array is not empty as when I view source the codes is there. Any idea how to solve this problem?

<%

Response.Write("<asp:TreeView ID='TreeView1' Runat='server'>");
Response.Write("<nodes>");

for (int i = 0; i < mainMenuNameQuantity; i++)
{
Response.Write("<asp:TreeNode Value='" + mainMenuNameArray + "' Expanded='False' Text='1'>");
Response.Write("<asp:TreeNode Value='Child1A' Text='A' />");

Response.Write("</asp:TreeNode>");


}
Response.Write("</nodes>");
Response.Write("</asp:TreeView>");
%>
 
Why are you using Response.write in script tags. That is classic ASP coding. Use the codebehind file for all code.
 
All you are doing is writing out <asp:TreeNode> to the client so no menu will appear (i.e. it will appear as text in the user's browser!). If you want to create dynamic controls with associated events, have a look at the example here:

[URL unfurl="true"]http://wiki.lessthandot.com/index.php/ASP.NET:_Add_dynamic_controls_with_events[/url]

Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Website Design
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
Dear Jbsenson,
Can you give me some reference site where I can refer this? Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top