| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2025 人关注过本帖
标题:treeview gridview 和框架结合使用的问题?请指点
只看楼主 加入收藏
tslcyh
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-1-6
收藏
 问题点数:0 回复次数:1 
treeview gridview 和框架结合使用的问题?请指点
最近做了个文档管理系统,使用treeview和gridview,tree放在左框架里,gridview放在主框架里.
tree的节点是由数据库动态生成的,通过判断选择了节点的,主框架里的gridiew显示不同的内容.如果不使用框架,就把tree和gridview放在一个页面下了,测试能成功.但是放在框架后,第一次必须选择节点两次才触发gridview显示.同时我原来在页面下能实现的删除事件和打开选中事件也都失效了.恳请各路高手伸出援助之手.主要代码如下.
treeview的selectednodechanged事件的代码
protected void TV_SelectedNodeChanged(object sender, EventArgs e)
    {   
        string depth = TV.SelectedNode.Depth.ToString();
        string nodetext = TV.SelectedNode.Text.ToString();
        string nodeparent;
        switch (depth )//若为根节点不传父节点,不然会得到空值
        {
            case "0":               
                TV.SelectedNode.NavigateUrl = "main.aspx?nodetext="+nodetext+"&depth="+depth ;
                break;
            case "1":
                TV.SelectedNode.NavigateUrl = "main.aspx?nodetext=" + nodetext + "&depth=" + depth;
                break;
            case "2":
                nodeparent =TV.SelectedNode .Parent .Text .ToString ();
                TV.SelectedNode.NavigateUrl = "main.aspx?nodetext=" + nodetext + "&depth=" + depth+"&nodeparent="+nodeparent ;
                break;
            default :
                break;
    }
    }
主框架里的main.aspx的代码

 protected void DataBinds()
    {//传回所选节点文本,父节点文本和所选节点深度
         
        int depth = Convert.ToInt32(Request .QueryString ["depth"].ToString ());
        string nodeselect = Request.QueryString["nodetext"].ToString();      
        SqlConnection objConnection = new SqlConnection(strConnection);  
        switch (depth)
           {
            case 0:

                //所选节点为系统.
                String strSQL0 = "select * from DocInfo where DepName='" + nodeselect  + "'";
                SqlDataAdapter da0 = new SqlDataAdapter(strSQL0, objConnection);
                DataSet Result0 = new DataSet();
                da0.Fill(Result0);
                //绑定数据到GridView
                this.GridView1.DataSource = Result0;
                GridView1.DataKeyNames = new string[] { "DocID" };
                this.GridView1.DataBind();
                break;
            case 1:
                //所选节点为项目
                //绑定数据到GridView
                String strSQL1 = "select * from DocInfo where ProName='" + nodeselect  + "'";
                SqlDataAdapter da1 = new SqlDataAdapter(strSQL1, objConnection);
                DataSet Result1 = new DataSet();
                da1.Fill(Result1);
                this.GridView1.DataSource = Result1;
                GridView1.DataKeyNames = new string[] { "DocID" };
                this.GridView1.DataBind();
                break;
            case 2:
                //所选节点为类别
                //绑定数据到GridView
                string nodeparent = Request.QueryString["nodeparent"].ToString();
                String strSQL2 = "select * from DocInfo where ProName='" +nodeparent  + "'and lbName='" + nodeselect  + "' ";
                SqlDataAdapter da2 = new SqlDataAdapter(strSQL2, objConnection);
                DataSet Result2 = new DataSet();
                da2.Fill(Result2);
                this.GridView1.DataSource = Result2;
                GridView1.DataKeyNames = new string[] { "DocID" };
                this.GridView1.DataBind();
                break;
            default:
                // 显示信息.
                break;
              }
        }

删除选中事件代码,我这里是在页面里加了一个button控件的.gridview模板列里放了checkbox

protected void btnDeleteCheck_Click(object sender, EventArgs e)
    {
        String sqlText = "(";

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {

            CheckBox cbx = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
            if (cbx.Checked == true)
            {
                sqlText = sqlText + Convert.ToInt32(GridView1.DataKeys[i].Value) + ",";

            }
        }
        sqlText = sqlText.Substring(0, sqlText.Length - 1) + ")";
        sqlText = "delete DocInfo where DocID in" + sqlText;

        try
        {
            //执行删除语句
            SqlConnection conn = new SqlConnection(strConnection);
            conn.Open();
            SqlCommand cmd = new SqlCommand(sqlText, conn);
            int delCount = Convert.ToInt32(cmd.ExecuteNonQuery()); //删除记录数量
            Response.Write("<script>alert('共删除" + delCount + "条数据');</script>");
            DataBinds();
        }
        catch (Exception ex)
        {
            //若有错误发生,输出错误信息
            Response.Write("<script>alert('您没有选中任何数据');</script>");

        }
    }

打开选中事件,也是另加了一个button控件
protected void btnOpen_Click(object sender, EventArgs e)
    {
        
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {

            CheckBox cbx = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
            if (cbx.Checked == true)
            {
                int DocID = Convert.ToInt32(GridView1.DataKeys[i].Value);               
                Response.Redirect("openfile.aspx?DocID=" + DocID);//这里是一个下载二进制流的aspx

            }
        }
请问这是为什么??(当然若tree和gridview放在一个页面下,绑定函数略有不同,但方法是一样的,只不过不需要传值了,只需通过tV.Node.Depth/TV.SelectedNode.Text/TV.SelectedNode.Parent.Text来定义查询语句就可以了)
1.为什么tree选择节点两次才显示数据.
2.我的删除事件和打开选中事件都不能执行,为什么?
搜索更多相关主题的帖子: gridview treeview 框架 数据库 节点 
2008-01-06 21:31
hex_maddog
Rank: 1
等 级:新手上路
帖 子:116
专家分:0
注 册:2007-11-21
收藏
得分:0 
1.控件有没有IsPostBack,去掉第一个问题就解决了
2.框架那就是两个页面了哦,你把按钮的函数发上来没用
2008-01-08 18:53
快速回复:treeview gridview 和框架结合使用的问题?请指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021704 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved