秋天来啦,秋天来啦;天空像一块覆盖在大地上的蓝宝石,它已经给秋风抹试得洁净而明亮。棉花笑嘻嘻的来了,它听说好朋友—秋姑娘来了,笑的咧开了嘴。玉米在房顶上唱着歌跳着舞,别提多开心了。路边两只黑色的小狗在玩耍,看它那可爱的样子,让人忍不住的笑。石榴也许太兴奋了,竟然笑破了肚皮,苹果跑着来了,当然脸蛋是红彤彤的。
private void Display() {
dt = new TsOrganize().OrganizeDs();
DataView dv = new DataView(dt);
TreeNode nodes = new TreeNode();
nodes.Text = "两岸咖啡";
nodes.Value = "0";
if (dt.Rows.Count >= 1)
{
dv.RowFilter = "fParentId=''";
if (dv.Count >= 1)
{
foreach (DataRowView drrow in dv)
{
TreeNode nodel = new TreeNode();
nodel.Text = drrow.Row["fOrgName"].ToString();
nodel.Value = drrow.Row["forgNo"].ToString();
nodes.ChildNodes.Add(nodel);
NodeList(dv, nodel, drrow.Row["fOrgNo"].ToString());
}
}
}
treevList.Nodes.Add(nodes);
} //生成树
private void NodeList(DataView dv, TreeNode node, string ParentId)
{
dv.RowFilter = "fParentId='" + ParentId.ToString() + "'";
if (dv.Count >= 1)
{
foreach (DataRowView drrow in dv)
{
TreeNode nodel = new TreeNode();
nodel.Text = drrow.Row["fOrgName"].ToString();
nodel.Value = drrow.Row["forgNo"].ToString();
node.ChildNodes.Add(nodel);
NodeList(dv, nodel, drrow.Row["fOrgNo"].ToString());
}
}
}
============================================================
1.
TreeNodeCollection tnc = treevList.CheckedNodes;
//获取树中所有选定的节点
private void GetCheckNode(TreeNodeCollection tnc)
{
foreach (TreeNode node in tnc)
{
if(node.Checked)
{
if (node.ChildNodes.Count == 0)
{
DataRow dr = tblSelChains.NewRow();
dr["forgNo"] = node.Value;
dr["fOrgName"] = node.Text.ToString();
tblSelChains.Rows.Add(dr);
}
}
}
} 2.根据根据数据库中的值,给相应的节点的CHECKED=true /// <summary>
///dtPloyStore :是表(保存从数据库中读取的数据)
/// <para></para>
/// </summary>
TreeNodeCollection tnc = treevList.Nodes ;
if (dtPloyStore != null)
{
if (dtPloyStore.Rows.Count > 0)
{
for (int i = 0; i < dtPloyStore.Rows.Count; i++)
{
GetSelectedTreeNode(tnc, dtPloyStore.Rows[i]["fOrgNo"].ToString());
}
}
}
/// <summary>
/// 遍历门店树,得到选中的节点
/// <para></para>
/// </summary>
/// <param name="tnc"></param>
public void GetSelectedTreeNode(TreeNodeCollection tnc,string CheckData)
{
foreach (TreeNode node in tnc)
{
if (node.Checked)
{
node.Checked = true;
break;
}
GetSelectedTreeNode(node.ChildNodes, CheckData);
}
} 3.javascript实现选中父节点,子节点自动选中
///后台给treeview添加属性
/// this.treevList.Attributes.Add("onclick", "OnTreeNodeChecked()"); ///下面是在前台javascript中编写的
function OnTreeNodeChecked() {
var ele = window.event.srcElement;
if (ele.type == 'checkbox') {
var childrenDivID = ele.id.replace('CheckBox', 'Nodes');
var div = document.getElementById(childrenDivID);
if (div == null) return;
var checkBoxs = div.getElementsByTagName('INPUT');
for (var i = 0; i < checkBoxs.length; i++) {
if (checkBoxs[i].type == 'checkbox')
checkBoxs[i].checked = ele.checked;
}
}
4.在 treeview上显示CHECKBOX,其实很简单,只要设置 ShowCheckBoxes="All"
如果我们想显示treeviw的设定层,我们可以设置 ExpandDepth="N" (N为数字,就是你想显示的层数,0为全部层)
到此这篇关于asp.net treeview checkbox 相关问题就介绍到这了。有人说,青春仿佛是朵素洁的昙花,来不及铺张来不及遐思,甚至来不及弥补欠缺和瑕庛,就那么匆匆地谢了。更多相关asp.net treeview checkbox 相关问题内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!