绑定时:
private void BindInfo()
{
stv1.Nodes.Clear();
InitTree();
BindTree(stv1.Nodes, PositionID);
stv1.ExpandAll();
}
部分代码:
记得给结点添加孩子结点时,要先定义该孩子结点,然后再在结点集的孩子结点上添加该孩子结点。
TreeNode tn2 = null;
foreach (DataRow dr in _dataTable.Select("ID='" + parentId + "'"))
{
tn2 = new TreeNode(dr["Name"].ToString() + " <a href='#' οnclick='javascript:window.open(/"AA.aspx?C=" + dr["ID"].ToString() + "/", /"/", /"height=650,width=600,top=300,left=400,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no/");return false;' target='_blank' style='color:#3B96DD'>匹配</a>", dr["CompetenceID"].ToString());
tn2.ToolTip = "名称:" + dr["CompetenceName"].ToString();
tn2.Checked = true;
tn.ChildNodes.Add(tn2);
}
弹出页面要实现的功能是弹出选择后关闭,同时传参给父页面,然后刷新父页面
protected void DoPost(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(hfList.Value.Trim()))
{
if (Session["c"] != null && Session["c"].ToString() != "")
Session["c"] = Session["c"].ToString() + "@" + hfList.Value;
else
Session["c"] = hfList.Value;
Response.Write("<script> window.opener.location.href=window.opener.location.href;window.close();</script>");
Response.End();
}
}
如果有多层都要实现动态选择绑定,要记得使用串接然后再进行拆分
if (Session["c"] != null && Session["c"].ToString() != "")
{
string[] cArray = Session["c"].ToString().Split('|');
for (int i = 0; i < cArray .Length; i++)
{
C_Info cinfo = new C_Info();
cinfo.CID = new Guid(cArray [i]);
if (cinfo.Exist())
{
TreeNode tn3 = null;
tn3 = new TreeNode(cinfo.CName, cinfo.iD.ToString());
tn3.ToolTip = "名称:" + cinfo.Name;
tn3.Checked = true;
tn.ChildNodes.Add(tn3);
Bind2(tn3.ChildNodes, cinfo.CID);
}
}
}