asp.net¶¯Ì¬Éú³ÉTreeView
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class left : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GetTreeView();
}
private void GetTreeView()
{
try
{
string connectionstring = "Server=(local);uid=sa;pwd=123456;database=web";//Á¬½ÓSQLÊý¾Ý¿â
SqlConnection conn = new SqlConnection(connectionstring);
string sql = "select * from menu where menu_level=1 and parent_id =0";//²éѯһ¼¶½Úµã
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
DataSet ds1 = new DataSet();
adapter.Fill(ds1, "temp");
DataTable table1 = ds1.Tables["temp"];//°Ñ¶ÁÈ¡µÄÊý¾Ý·ÅÈëDATATABLEÖÐ
TreeView1.Nodes.Clear();//½¨Á¢¸ù½Úµã£¬±éÀú¡£
foreach (DataRow dr1 in table1.Rows)
{
TreeNode root = new TreeNode();
&
Ïà¹ØÎĵµ£º
×î½üÑо¿ÁËÒ»ÏÂtreeview£¬·¢ÏÖÓÐÁ½ÖÖʵÏÖÎÞÏÞ¼¶Ê÷µÄ·½·¨£¬ÎÄ×Ö²»Ïë¶àд£¬Ö±ÈëÖ÷Ìâ¡£
ÏÈ¿´¿´Êý¾Ý¿â±íµÄÉè¼Æ£¬Êý¾Ý±íÖ÷Òª°üÀ¨ID£¬Name£¬ParentIDÕâÈýÏÆäÖÐIDÊÇÖ÷¼ü£¬ParentID¶ÔÓ¦½ÚµãµÄ¸¸½Úµã£º
·½·¨Ò»£ºÓõݹé±éÀúÊý¾Ý£¬²¢½«½ÚµãÖð¸öÌí¼Óµ½treeviewÖÐÈ¥¡£
1.ÏȽøÐÐÊý¾Ý¿âÁ¬½ÓºÍÊý¾ÝµÄ¶ÁÈ¡£¬²¢½«¸ù½ÚµãÏÈÌí¼Ó½øtreeview ......
ASP.NET MVCºÍWebForm¸÷Óи÷µÄÓŵ㣬ÎÒÃÇ¿ÉÄÜÐèҪͬʱʹÓÃASP.NET MVCºÍWebForm¡£±¾ÎĽéÉÜÁËÈçºÎÔÚASP.NET MVCÏîÄ¿ÖÐʹÓÃWebForm¡£
Ê×ÏÈн¨Ò»¸öÃûΪWebFormsµÄÎļþ¼ÐÓÃÓÚ´æ·ÅWebForm£¬²¢Ìí¼ÓÒ»¸öWeb´°ÌåÎļþDemo.aspx×÷ΪÑÝʾ¡£
Demo.aspx¾Í¼òµ¥µÄÊä³öÒ»¾ä»°“It’s a WebForm.”
¹Ø¼ü²½ÖèÔÚÓÚ·ÓÉÉèÖá ......
1.<%=...%>Óë<%#... %>µÄÇø±ð:
´ð:<%=...%>ÊÇÔÚ³ÌÐòÖ´ÐÐʱµ÷Óã¬<%#... %>ÊÇÔÚDataBind()·½·¨Ö®ºó±»µ÷ÓÃ
2.¿Ø¼þ½ÓÊÕÄÄЩÀàÐÍÊý¾Ý?
´ð:½ÓÊÕBindµÄ¿Ø¼þ£¬Ò»°ãÓÐDropDownList,DataList,DataGrid,ListBoxÕâЩ¼¯ºÏÐÔÖÊ ......