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为全部层)
{
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为全部层)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“asp.net treeview checkbox 相关问题”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。