CREATE TABLE area (
areaid INT IDENTITY NOT NULL,
areaname VARCHAR ( 50 ),
Fatherld INT,
CONSTRAINT PK_area PRIMARY KEY NONCLUSTERED (areaid)
)
insert into area(areaname ,Fatherld) values('root1',-1)
insert into area(areaname ,Fatherld) values('child1',1)
insert into area(areaname ,Fatherld) values('child2',1)
1、数据库SQL2.X 或ACCESS
2、要实现的内容:
1.1当点击getdata.aspx的 BUTTON获取数据是,弹出getdata.aspx的.
1.2当选定dtrees.aspx页面(本树是用dtree实现)的中的结点时,在getdata.aspx的
ID:<input id="tareaid" type="text" runat="server" />
Areaname<input id="tareaname" type="text" runat="server" />
显示内容所选取的areaname,areaid
(注意:用Ajax实现)
小弟在此感谢大家!
下面是两个页面代码(我不知道,怎么上传文件提问, 不好意思,晒码了.):
dtrees.aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="dtrees.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="StyleSheet" href="css/dtree.css" type="text/css" >
<script type="text/javascript" src="js/dtree.js" ></script>
<script language="javascript" >
function gourl(id)
{
alert(id);
}
</script>
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div style="z-index: 102; left: 30px; width: 100px; position: absolute; top: 47px;
height: 12px" >
<asp:Label ID="Label1" runat="server" Width="158px"></asp:Label></div>
</form>
</body>
</html>
dtrees.aspx后台:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string jtree = "<script type=\"text/javascript\">\n";
jtree += "d = new dTree('d');\n";
DataTable dt = LinqToDataTable();
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
jtree += "d.add(" + dr[0] + "," + dr[2] + ",'" + dr[1] + "','javascript:gourl(" + dr[0] + ")');";
}
jtree += "document.write(d);";
jtree += "</script>";
this.Label1.Text = jtree;
}
}
public System.Data.DataTable LinqToDataTable()
{
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["constring"].ConnectionString.ToString());
SqlDataAdapter da = new SqlDataAdapter("select * from area order by areaid asc", conn);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
getdata.aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="getdata.aspx.cs" Inherits="getdata" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div> ID:<input id="tareaid" type="text" runat="server" />
Areaname<input id="tareaname" type="text" runat="server" />
<asp:Button ID="Button1" runat="server" Text="获取数据" />
</div>
</div>
</form>
</body>
</html>
getdata.aspx后台:
请自定义,,
如果实现或看不明白的,邮箱:chenxuebo03@163.com QQ45433621
联系!分数贴上!
如果你使用thickbox 插件或者其他同样实现弹出效果的插件的话,很简单:
首先在getdata页面增加一个js方法比如:function update〔id,text〕{赋值 逻辑操作;}
getdata页面input 触发弹出窗口-->在dtrees页面选中目标-->点击确定触发事件window.parent.update(areaID,areaname);window.parent.tb_remove();//关闭弹出窗
主要看你是要怎么弹出窗口的问题,推荐thickbox
你是想做个撒功能?
你可以研究一下UpdatePanel的用法
在你的控件外面嵌套一个UpdatePanel就可以了
你的问题应该是将子页面中选择节点的ID以及Name传递给父页面的相关表单元素的!!
你可以尝试在dtrees.aspx页面给节点绑定个js方法,js方法的大概实现类似于这样
function SetParentValue(id,value){
window.parent.document.all["tareaid"].value = id;
window.parent.document.all["tareaname"].value =value;
}
<asp:Button ID="Button1" runat="server" Text="获取数据" />
asp的控件,这还叫ajax吗?都没有看到在哪个调用脚本那~~~