Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to poulate data from database in treeview??

how to poulate data from database in treeview??

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-nettutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    biswa47
    wrote on last edited by
    #1

    Hai frinedz,i want to populate data from Database in hirachary manner. i have done up to 2level. but i dont know how to add one subchild in the child node...can u plz do this with my existing code... or tell me where should i add the code to a sub child under the child node. here the parent node is -modulename child node - componentname & subchild node- function name. in the sqlcommand you can put any sql....for ur conviennet .later on iwill change it according to my requirment. plz do this favour on me. i am using asp.net along with c# 2005 as front end and backend as sqlserver2005 as db below i am giving u my code also.. ====================================== protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PopulateRootLevel(); } } void PopulateRootLevel() { SqlConnection SqlCon = new SqlConnection("Data Source=biswa;Initial Catalog=rwsNew;User ID=sa;Password=biswa007"); // SqlConnection SqlCon = new SqlConnection("Data Source=;Initial Catalog=rwsNew;User ID=;Password="); SqlCon.Open(); SqlCommand SqlCmd = new SqlCommand("SELECT modulename,moduleid FROM module_master WHERE delflag='ACTIVE' ORDER BY modulename ", SqlCon); SqlDataReader Sdr = SqlCmd.ExecuteReader(); SqlCmd.Dispose(); string[,] ParentNode = new string[100, 2]; int count = 0; while (Sdr.Read()) { ParentNode[count, 0] = Sdr.GetValue(Sdr.GetOrdinal("moduleid")).ToString(); ParentNode[count++, 1] = Sdr.GetValue(Sdr.GetOrdinal("modulename")).ToString(); } Sdr.Close(); for (int loop = 0; loop < count; loop++) { TreeNode root = new TreeNode(); root.Text = ParentNode[loop, 1]; root.Target = "_blank"; //root.NavigateUrl = "Default.aspx"; SqlCommand Module_SqlCmd = new SqlCommand("SELECT compid,componentname FROM module_component WHERE (moduleid = '" + ParentNode[loop, 0] + "') ", SqlCon); SqlDataReader Module_Sdr = Module_SqlCmd.ExecuteReader(); while (Module_Sdr.Read()) { TreeNode child = new TreeNode(); child.Text = Module_Sdr.GetValue(Module_Sdr.GetOrdinal("componentname")).ToString(); child.Target = "_blank"; //child.NavigateUrl = "Default.aspx"; root.ChildNodes.Add(child); } Module_Sdr.Close(); Tv

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups