当前位置: 代码迷 >> C# >> C#中怎样实现点击左侧的treeview节点右首Iframe里面的Gridview变化
  详细解决方案

C#中怎样实现点击左侧的treeview节点右首Iframe里面的Gridview变化

热度:24   发布时间:2016-05-05 03:52:16.0
C#中怎样实现点击左侧的treeview节点右侧Iframe里面的Gridview变化?
想做一个页面,实现下面的功能,该页面叫Menufecturing Method。

左面一个TreeView点击相应的节点,在右面的iframe中显示绑定的数据,实现对SQL数据库表的显示。该页面叫MethodIframe
iframe框架如下图


目前在Menufecturing Method里面前台代码:

</head>
<body style="padding-top: 0px; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; ">
     <form id="form1" runat="server">
     <div style="height: 833px">
   
      <table style="height: 863px; width: 1005px"  >
             <tr>
               <td valign="top" class="style1" > 
                   <asp:TreeView ID="TreeView1" runat="server" ShowLines="True">
                   </asp:TreeView>
                 </td>

                  <td valign="top" >
                   <iframe src=MethodIframe.aspx 
                       style="width:815px; height: 675px" frameborder=0 scrolling=yes id="I1" 
                        name="I1"></iframe>
                </td>
            </tr>
      </table>
    </div>                
     </form>                
</body>
</html>


后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient ;
using System.Configuration;


public partial class Manufacturing_Method_Manufacturing_Method : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                treedata();
                tabledata();
                tabledata1();
            }
               
            }
    protected void treedata()
        {

        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = "Data Source=BUAA-TORNADO;Initial Catalog=knowledgebase;Integrated Security=True";
        conn.Open();
                SqlDataAdapter ada = new SqlDataAdapter("select * from TestPart114_Basic", conn);
                SqlDataAdapter ada1 = new SqlDataAdapter("select * from TestPart114_Decomposition", conn);
                DataSet ds = new DataSet();
                DataSet ds1 = new DataSet();
                ada.Fill(ds);
                ada1.Fill(ds1);


                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string node = ds.Tables[0].Rows[i][1].ToString();

                    TreeNode nodes = new TreeNode();
                    nodes.Text = node;
                    nodes.Value = ds.Tables[0].Rows[i][0].ToString();
                    nodes.ImageUrl = "~/image/文件夹.png";

                    //nodes.NavigateUrl = "WebForm1.aspx";
                    //nodes.Target = "menu1";

                    


                    TreeView1.Nodes.Add(nodes);
                }


                for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                {
                    string node = ds1.Tables[0].Rows[i][1].ToString();

                    TreeNode nodes = new TreeNode();
                    nodes.Text = node;
                    nodes.Value = ds1.Tables[0].Rows[i][0].ToString();
                    nodes.ImageUrl = "~/image/资源树.png";

                    TreeView1.Nodes[0].ChildNodes.Add(nodes);
                }


                conn.Close();
            

        }

        protected void tabledata()
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=BUAA-TORNADO;Initial Catalog=knowledgebase;Integrated Security=True";
            conn.Open();
            SqlDataAdapter ada = new SqlDataAdapter("select * from TestPart114_Decomposition", conn);
            DataSet ds = new DataSet();
            ada.Fill(ds);

            GridView1.DataSource = ds;
            GridView1.DataBind();

             

            conn.Close();

        }

        protected void tabledata1()
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=BUAA-TORNADO;Initial Catalog=knowledgebase;Integrated Security=True";
            conn.Open();
            SqlDataAdapter ada = new SqlDataAdapter("select * from TestPart114_Basic", conn);
            DataSet ds = new DataSet();
            ada.Fill(ds);

            GridView2.DataSource = ds;
            GridView2.DataBind();


            conn.Close();

        }


        #region 测试用的
        protected void tabletest()
        {

            DataTable auto = new DataTable();
            auto.Columns.Add("ID");
            auto.Columns.Add("Name"); 
            auto.Columns.Add("Text");
            for (int i = 1; i <= 10; i++)
            {
                string txt = "选项" + i;
                string txt_1 = "文本" + i;
                auto.Rows.Add(new object[] { i, txt,txt_1 });
            }
             GridView2.DataSource = auto;
            GridView2.DataBind();
           
        }
        #endregion

        protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            string stext = TreeView1.SelectedNode.Text;//获得点击的文本
            string svalue = TreeView1.SelectedNode.Value;
      tabledata1();
        }
 }



------解决思路----------------------
1.百度搜 框架网页 第一个 
2.TrreView的点击事件取值,给Iframe 的SRC重新赋值实现绑定
3.不涉及跨域的情况下可以直接操作Iframe里面的dom元素,不要使用GridView  使用json来实现表格绑定
------解决思路----------------------
点击左侧的TreeView节点、右侧GridView控件呈现数据库数据显示示例
//TreeView控件设置
<asp:TreeView ID="TreeView1" runat="server" Height="241px" Font-Size="12pt" ForeColor="Black" Width="121px" style="left: 1px; position: relative; top: -64px" ImageSet="Faq" >
            <Nodes>
                <asp:TreeNode Text="后台管理" ToolTip="后台管理" Value="后台管理">
                   
               
               <asp:TreeNode Text="系统管理" ToolTip="系统管理" Value="系统管理">
                <asp:TreeNode Text="管理员" ToolTip="管理员" Value="管理员" Target="rightFrame" NavigateUrl="AdminManage.aspx"></asp:TreeNode>
                    <asp:TreeNode Text="类型管理" ToolTip="类型管理" Value="类型管理" Target="rightFrame" 
                       NavigateUrl="~/Module/Admin/BlogType.aspx"></asp:TreeNode>//codego.net/11/1/1/
                 </asp:TreeNode>
//点击管理员管理GridView控件呈现数据;
 <asp:GridView ID="gvAdmin" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" Font-Size="9pt" Width="500px" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" Font-Bold="False" OnRowDataBound="gvAdmin_RowDataBound">
                                    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                    <Columns>
                                        <asp:BoundField HeaderText="管理员ID" DataField="ID" />
                                        <asp:BoundField HeaderText="用户名" DataField="UserName" />
                                        <asp:BoundField HeaderText="管理员性别" DataField="Sex" />
                                        <asp:BoundField HeaderText="QQ" DataField="QQ" />
                                        <asp:BoundField HeaderText="注册时间" DataField="RegTime" />
                                        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="AdminInfo.aspx?ID={0}"
                                            HeaderText="详细信息" Text="详细信息" />
                                        <asp:CommandField ShowDeleteButton="True" HeaderText="删除" />
                                    </Columns>
                                    <SelectedRowStyle BackColor="#C5BBAF" ForeColor="#333333" Font-Bold="True" />
                                    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                    <AlternatingRowStyle BackColor="White" />
                                    <RowStyle BackColor="#E3EAEB" />
                                    <EditRowStyle BackColor="#7C6F57" />
                                </asp:GridView>

------解决思路----------------------
简单点,不同的数据放在不同的.aspx文件中显示。这样你的treeview节点负责重定向iframe的内容页url就OK了。
treeview的Click事件中写 Response.Redirect(URL); 相应的page中准备数据显示。
另一种方式,1个page里面放几个Panel,TreeView控制显示和隐藏。
  相关解决方案