日期:2014-05-18  浏览次数:20590 次

treeview的结点


请位各位。treeview中,结点是不是可以触一个事件的。
如上图,我想点一下某个学生的信息,即改变label的text
这些值都有数据库里面了,而且结点的value值是所要显示学生信息记录的id

请各指教,急急急。谢谢!!!!!!!!!


------解决方案--------------------
HTML code
<%@ Page Language="C#" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    protected void Page_Load(object sender, EventArgs e)
    {
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            using (SqlDataAdapter da = new SqlDataAdapter(SQLString, conn))
            {
                using (DataTable dt = new DataTable())
                {
                    conn.Open();
                    da.Fill(dt);
                    conn.Close();
                    foreach (DataRow dr in dt.Rows)
                    {
                        this.TreeView1.Nodes.Add(new TreeNode(dr["stu_name"].ToString(), dr["stu_id"].ToString()));
                    }
                }
            }
        }
    }

    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            conn.Open();
            using (SqlCommand comm = new SqlCommand("SELECT * FROM stu_table WHERE stu_id='" + this.TreeView1.SelectedNode.Value + "'", conn))
            {
                using (SqlDataReader dr = comm.ExecuteReader())
                {
                    // show data 
                }
            }
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TreeView ID="TreeView1" runat="server" ShowLines="true" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">
            </asp:TreeView>
            <asp:Label ID="Label1" runat="server"></asp:Label>
        </div>
    </form>
</body>
</html>

------解决方案--------------------
HTML code
<%@ Page Language="C#" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    protected void Page_Load(object sender, EventArgs e)
    {
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            using (SqlDataAdapter da = new SqlDataAdapter(SQLString, conn))
            {
                using (DataTable dt = new DataTable())
                {
                    conn.Open();
                    da.Fill(dt);
                    conn.Close();
                    foreach (DataRow dr in dt.Rows)
                    {
                        this.TreeView1.Nodes.Add(new TreeNode(dr["stu_name"].ToString(), dr["stu_id"].ToString()));
                    }
                }
            }
        }
    }

    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            conn.Open();
            using (SqlCommand comm = new SqlCommand("SEL