弹出窗口TreeView与ListBox结合显示信息并返回给页面

具体的功能是点击一个按钮,然后弹出一个窗口,窗口里面左侧是一个treeview,右侧是一个listbox。点击左侧的treeview进行选择信息,右侧的listbox根据选择的节点显示相应的信息。弹出窗口为两个iframe,关闭弹出窗口有待解决。

选择按钮处代码如下所示

<tr>
                        <td class="TableData" nowrap>
                            故障设备:</td>
                        <td nowrap class="TableData" colspan="3">
                            <asp:TextBox ID="ToolName" runat="server" TextMode="SingleLine" Rows="1" CssClass="BigStatic" Columns="25" ReadOnly="True" msg="设备名称" Width="438px"></asp:TextBox>
                            <INPUT id="btnSelectSendRange" class="SmallButton" οnclick="SelectRoad(ToolName,ToolID);"  type="button" value="选 择" name="Button11">
                            <asp:Button
                                ID="Button2" runat="server" class="SmallButton"  Text="清 空" OnClick="Button2_Click" />
                            <input id="ToolID" type="hidden" name="CopyRoadID" runat="server" style="width: 22px">
                        </td>
                    </tr>
<script language="javascript">
    function SelectRoad(objCopyTollName,objCopyTollID)
    {
	var value = window.showModalDialog("../../EquTpye/EquToolManage/SelectPlaceMain.aspx", "", 'dialogHeight=420px;dialogWidth=450px;status=no;resizable:no;help:no');
	if(value==null || value=="")
	{
		return;
	}
	var words = value.split('|')
	objCopyTollName.innerText = words[1];
	objCopyTollID.innerText=words[0];
}
    </script>

选择完之后将text显示在input里面,ID存入hidden的input里面

弹出窗口的主页面:

<frameset cols="230,*"  FRAMEBORDER="yes" border="1" framespacing="0" id="bottom">
   <frame name="Place" src="Place.aspx"></frame>
   <frame name="Tool" src="Tool.aspx"></frame>
</frameset>

Place.aspx页面为treeview页面,代码如下:

<script>
    function info(id)
    { 
        window.parent.frames["Tool"].location="Tool.aspx?ID="+id;
    }
</script>
其中TV为控件ID,后台代码:
protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                AddTree("", (TreeNode)null);
            }
        }
        protected void AddTree(string PlaceValue, TreeNode TNode)
        {
            DBConnect db = new DBConnect();
            DataView DvTree = new DataView();
            string sql = "";
            if (PlaceValue == "")
            { sql = "select * from TEquPlace where len(PlaceID)=3"; }
            if (PlaceValue.Length >= 3)
            { sql = "select * from TEquPlace where PlaceID like '" + PlaceValue.ToString() + "__' and len(PlaceID)=" + (Convert.ToInt32(PlaceValue.Length) + 2); }
            DataTable dt = db.ExecuteDataTable(sql);
            if (dt == null)
            { return; }
            DvTree.Table = dt;
            foreach (DataRowView row in DvTree)
            {
                TreeNode Node = new TreeNode();
                if (TNode == null)
                {
                    Node.Value = row["PlaceID"].ToString();
                    Node.Text = row["PlaceName"].ToString();
                    TV.Nodes.Add(Node);
                    AddTree(row["PlaceID"].ToString(), Node);
                }
                else
                {
                    Node.Value = row["PlaceID"].ToString();
                    Node.Text = row["PlaceName"].ToString();
                    TNode.ChildNodes.Add(Node);
                    AddTree(row["PlaceID"].ToString(), Node);
                }
            }
        }

        protected void TV_SelectedNodeChanged(object sender, EventArgs e)
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<Script>info('" + TV.SelectedNode.Value.ToString() + "')</Script>");
        }

lstSelected为listbox控件ID,tool.aspx页面,为listbox页面:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadList();
            }
        }        
        protected void LoadList()
        {
            string PlaceID = Request.QueryString["ID"];
            DBConnect db = new DBConnect();
            DataTable dt = db.ExecuteDataTable("select a.*,b.* from dbo.TEquLibrary a,TEquToolsType b where a.ToolTypeID=b.ToolTypeID and ItemTypeID=20 and PlaceID='" + PlaceID + "'");
            if (dt != null)
            {
                Label1.Visible = false;
                lstSelected.Visible = true;
                Button1.Visible = true;
                lstSelected.DataSource = dt;
                lstSelected.DataTextField = "ToolType";
                lstSelected.DataValueField = "LibraryID";
                lstSelected.DataBind();
            }
            else
            {
                lstSelected.Visible = false;
                Label1.Visible = true;
                Label1.Text = "当前位置无设备信息";
                Button1.Visible = false;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string LibraryID = "", ToolType = "";
            if (lstSelected.SelectedItem != null)
            {
                LibraryID = lstSelected.SelectedItem.Value;
                ToolType = lstSelected.SelectedItem.Text;
            }
            Response.Write("<script type='text/javascript'>window.returnValue='" + LibraryID + "|" + ToolType + "';</script>");            
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>window.top.close();</script>");
        
        }

具体实现:





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值