Asp. The method and related source of the TreeView and database binding in net
Source: Internet
Author: User
These days always see csdn someone asked the TreeView and database binding problem, just these days also made a this thing. There is also a TreeView-speaking article on the internet, but the search is on that one, and it is associated with access.
Here's how to implement it. The following are the implementation effects.
Step One: vs Web Development does not have the TreeView control, so first to the Microsoft website (http://msdn.microsoft.com/downloads/samples/internet/ASP_DOT_NET_ServerControls/
webcontrols/default.asp) go up and down the control, the site has a specific installation method, only the installation completed to use this control.
The second step: Database design
Look directly at the screenshot. The following is the design of the database.
Below is the value inside the database.
The following is the code, mainly using recursive algorithms to add the node to the TreeView. Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Using Microsoft.Web.UI.WebControls;
Using System.Data.SqlClient;
Using System.Configuration;
Namespace Testonline.treeview
... {
/**////<summary>
Summary description of the treeView1.
</summary>
public class TreeView1:System.Web.UI.Page
... {
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.CheckBox CheckBox1;
protected System.Web.UI.WebControls.Button Button1;
protected Microsoft.Web.UI.WebControls.TreeView TreeView3;
public static string Url= "Workstation Id=all;packet size=4096; uid=sa;password=;d ata source= (local);p the ersist security info=true;initial catalog=testonline; Max Pool size=500; Min Pool size=5 ";
Public SqlConnection myconnection=new SqlConnection (URL);
private void Page_Load (object sender, System.EventArgs e)
... {
Place user code here to initialize page
}
Web Forms Designer generated Code #region Web Forms Designer generated code
Override protected void OnInit (EventArgs e)
... {
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
/**////<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service