asp.net treeview checkbox 相关问题
作者:
asp.net treeview checkbox 相关问题,需要的朋友可以看下。
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为全部层)
您可能感兴趣的文章:
- asp.net Repeater取得CheckBox选中的某行某个值的c#写法
- asp.net gridview中用checkbox全选的几种实现的区别
- asp.net checkbox 动态绑定id GridView删除提示
- asp.net GridView控件中模板列CheckBox全选、反选、取消
- asp.net Javascript获取CheckBoxList的value
- asp.net 获取Datalist中Checkbox的值的小结
- ASP.NET Gridview与checkbox全选、全不选实现代码
- ASP.NET jQuery 实例5 (显示CheckBoxList成员选中的内容)
- ASP.NET jQuery 实例6 (实现CheckBoxList成员全选或全取消)
- ASP.NET jQuery 实例15 通过控件CustomValidator验证CheckBoxList
- asp.net CheckBoxList各项最小宽度CSS样式(兼容性good)
- ASP.NET中用js取CheckBoxList中值的方法实例
- ASP.NET服务器端控件RadioButtonList,DropDownList,CheckBoxList的取值、赋值用法
- ASP.NET DropDownListCheckBox使用示例(解决回发问题)
- ASP.NET中 CheckBox复选框控件的使用