
<%
@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>

<%
@ Control Language="c#" AutoEventWireup="false" Codebehind="SelUnit.ascx.cs" Inherits="DXK.Web.component.SelUnit" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

<script type="text/javascript">
//Sel_Text.onclick = function()
function clickSel(obj)

{
if(divTree.style.display == 'none')

{
divTree.style.display = '';
divTree.style.top = findOffsetTop(obj) + obj.offsetHeight;
divTree.style.left = findOffsetLeft(obj);
}
else

{
divTree.style.display = 'none';
}
}
document.onclick = function()

{
var the_obj = event.srcElement;
if ((the_obj.id.indexOf('_Sel_Text') == -1) && (get_ElementById(the_obj, 'divTree') == null))

{
if(divTree.style.display == '')
divTree.style.display = 'none';
}
}
function get_ElementById(the_ele,the_id)

{
the_id = the_id.toLowerCase();
if(the_ele.id.toLowerCase()==the_id)return the_ele;

while(the_ele=the_ele.offsetParent)
{
if(the_ele.id.toLowerCase()==the_id)return the_ele;
}
return(null);
}
function dodblclick(objTV, UCTag)

{
if(objTV.getTreeNode(objTV.clickedNodeIndex)!=undefined)

{
document.getElementById(UCTag+'_Sel_Text').value = objTV.getTreeNode(objTV.clickedNodeIndex).getAttribute("Text");
document.getElementById(UCTag+'_Sel_Value').value = objTV.getTreeNode(objTV.clickedNodeIndex).getAttribute("NodeData");
divTree.style.display = 'none';
}
}
function findOffsetTop(o)

{
var t = 0;
if (o.offsetParent)

{
while (o.offsetParent)

{
t += o.offsetTop;
o = o.offsetParent;
}
}
return t;
}
function findOffsetLeft(o)

{
var t = 0;
if (o.offsetParent)

{
while (o.offsetParent)

{
t += o.offsetLeft;
o = o.offsetParent;
}
}
return t;
}
</script>
<input id="Sel_Text" style="BACKGROUND-POSITION-X: right; BACKGROUND-IMAGE: url(../images/seltip.jpg); WIDTH: 150px; CURSOR: pointer; BACKGROUND-REPEAT: no-repeat"
readOnly type="text" runat="server"> <INPUT id="Sel_Value" type="hidden" runat="server">
<DIV id="divTree" style="BORDER-RIGHT: black 1px groove; BORDER-TOP: black 1px groove; DISPLAY: none; OVERFLOW: auto; BORDER-LEFT: black 1px groove; WIDTH: 240px; BORDER-BOTTOM: black 1px groove; POSITION: absolute; HEIGHT: 350px"><iewc:treeview id="tvUnitList" runat="server" BorderWidth="0px" BorderStyle="None"
Indent="20" SelectExpands="True" ShowToolTip="False"></iewc:treeview></DIV>


.cs后台代码
1
using System;
2
using System.Data;
3
using System.Drawing;
4
using System.Web;
5
using System.Web.UI.WebControls;
6
using System.Web.UI.HtmlControls;
7
using Microsoft.Web.UI.WebControls;
8
9
/**//// <summary>
10
/// SelUnit 的摘要说明。
11
/// </summary>
12
public class SelUnit : System.Web.UI.UserControl
13
{
14
protected System.Web.UI.HtmlControls.HtmlInputHidden Sel_Value;
15
protected System.Web.UI.HtmlControls.HtmlInputText Sel_Text;
16
protected Microsoft.Web.UI.WebControls.TreeView tvUnitList;
17
18
Property#region Property
19
/**//// <summary>
20
/// [只读]
21
/// </summary>
22
public string SelectedText
23
{
24
get
{return this.Sel_Text.Value;}
25
}
26
/**//// <summary>
27
/// [只读]
28
/// </summary>
29
public string SelectedValue
30
{
31
get
{return this.Sel_Value.Value;}
32
}
33
public string SelectedIndex
34
{
35
get
{return this.tvUnitList.SelectedNodeIndex;}
36
set
{this.tvUnitList.SelectedNodeIndex = value;}
37
}
38
public string CssClass
39
{
40
get
{return this.Sel_Text.Attributes["class"];}
41
set
{this.Sel_Text.Attributes.Add("class", value);}
42
}
43
public string Width
44
{
45
get
{return this.Sel_Text.Attributes["width"];}
46
set
{this.Sel_Text.Attributes.Add("width", value);}
47
}
48
public bool AutoPostBack
49
{
50
get
{return this.tvUnitList.AutoPostBack;}
51
set
{this.tvUnitList.AutoPostBack = value;}
52
}
53
private bool _Enabled = true;
54
public bool Enabled
55
{
56
get
{return this._Enabled;}
57
set
{this._Enabled = value;}
58
}
59
#endregion
60
61
private void Page_Load(object sender, System.EventArgs e)
62
{
63
// 在此处放置用户代码以初始化页面
64
Response.Buffer=true;
65
Response.ExpiresAbsolute=System.DateTime.Now.AddSeconds(-1);
66
Response.Expires=0;
67
Response.CacheControl="no-cache";
68
69
if(!Page.IsPostBack)
70
{
71
string strUserUnit = "z"; //默认为全省
72
if(Session["userinfo"] != null)
73
{
74
DataTable dtUserInfo = (DataTable)Session["userinfo"];
75
if(dtUserInfo.Rows.Count > 0)
76
strUserUnit = dtUserInfo.Rows[0]["user_unit"].ToString().Trim();
77
}
78
79
this.tvUnitList.Nodes.Clear();
80
this.InitStatUnitTree(ref this.tvUnitList, strUserUnit, false);
81
82
}
83
if(this._Enabled)
84
{
85
this.Sel_Text.Attributes.Add("onclick","javascript:clickSel(this);");
86
this.tvUnitList.Attributes.Add("ondblclick","javascript:dodblclick(this,'" + this.UniqueID + "');");
87
}
88
}
89
90
/**//// <summary>
91
/// 初始化单位列表,TreeView
92
/// </summary>
93
/// <param name="tv"></param>
94
/// <param name="strUserUnit"></param>
95
/// <param name="ifCheckBox"></param>
96
private void InitStatUnitTree(ref TreeView tv,string strUserUnit, bool ifCheckBox)
97
{
98
99
TreeNode tn = null;
100
TreeNode tnChild = null;
101
TreeNode tnGrandChild = null;
102
//TreeNode root = new TreeNode();
103
//root.Text = "单位列表";
104
//tv.Nodes.Add(root);
105
foreach(DataRow drUnit in dtUnit.Rows)
106

{
107
tn = DXK.Com.UICommon.tnGetTreeNode("mykey","myvalue");
108
tn.CheckBox = ifCheckBox;
109
tv.Nodes.Add(tn);
110
}
111
112
113
/**//// <summary>
114
/// 返回TreeNode
115
/// </summary>
116
/// <param name="strText"></param>
117
/// <param name="strData"></param>
118
/// <returns></returns>
119
public static TreeNode tnGetTreeNode(string strText,string strData)
120
{
121
TreeNode tn = new TreeNode();
122
tn.CheckBox = true;
123
tn.Text = strText;
124
tn.NodeData = strData;
125
return tn;
126
}
127
}
128
}
posted @
2007-09-19 12:35
blueKnight
Views(
1640)
Comments()
收藏
举报