c# 后台绑定treeview 单个tab

Posted 笑兮兮

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# 后台绑定treeview 单个tab相关的知识,希望对你有一定的参考价值。

<wijmo:C1TreeView ID="C1TreeView1" runat="server" ShowCheckBoxes="true" ShowExpandCollapse="true" Width="300px"></wijmo:C1TreeView>

<asp:Button ID="ButtonToTable" runat="server" Text="转表格" OnClick="ButtonToTable_Click" Width="58px" />



后台
 DataTable dtOil = GJPDbHelper.DAL.ExecuteDataSet("SELECT [品牌],[类型] FROM  [AIRB_MMTREE] where [treeType] = ‘1‘  group by [品牌],[类型]").Tables[0];
 
 BindTreeOil(dtOil);

        #region "Optional Interfaces"
 
        /// ----------------------------------------------------------------------------- 
        /// <summary> 
        /// Registers the module actions required for interfacing with the portal framework 
        /// </summary> 
        /// <value></value> 
        /// <returns></returns> 
        /// <remarks></remarks> 
        /// <history> 
        /// </history> 
        /// ----------------------------------------------------------------------------- 
        public ModuleActionCollection ModuleActions
        {
            get
            {
                ModuleActionCollection Actions = new ModuleActionCollection();
                Actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile),
                   ModuleActionType.AddContent, "", "add.gif", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit,
                    true, false);
                return Actions;
            }
        }
 
        #endregion
 
 
        /// <summary>
        /// 将数据绑定到C1TreeView1
        /// </summary>
        /// <param name="dtSource">传入两列数据</param>
        private void BindTreeOil(DataTable dtSource)
        {
 
            C1TreeView1.Nodes.Clear();
 
            string topNodeStr = "";
 
            C1TreeViewNode curNode = new C1TreeViewNode(); ;
 
            //DataRow[] rows = dtSource.Select(string.Format("ParentID={0}", parentID));
            foreach (System.Data.DataRow c1row in dtSource.Rows)
            {
                if (topNodeStr != Convert.ToString(c1row[0]))
                {
                    C1TreeViewNode newNode = new C1TreeViewNode();
                    newNode.Value = Convert.ToString(c1row[0]);
                    newNode.Text = Convert.ToString(c1row[0]);
 
                    C1TreeView1.Nodes.Add(newNode);
                    topNodeStr = Convert.ToString(c1row[0]);
                    curNode = newNode;
 
                    C1TreeViewNode newsubNode = new C1TreeViewNode();
                    newsubNode.Value = Convert.ToString(c1row[1]);
                    newsubNode.Text = Convert.ToString(c1row[1]);
 
                    curNode.Nodes.Add(newsubNode);
                }
                else
                {
                    C1TreeViewNode newNode = new C1TreeViewNode();
                    newNode.Value = Convert.ToString(c1row[1]);
                    newNode.Text = Convert.ToString(c1row[1]);
 
                    curNode.Nodes.Add(newNode);
 
                }
            }
        }
 
 
        /// <summary>
        /// 建立所选项目的目录框架
        /// </summary>
        /// <param name="ctrv"></param>
        /// <returns></returns>
        protected DataTable checkItemTableOil(C1TreeView ctrv)
        {
            InsusJsUtility js = new InsusJsUtility();
            Boolean itemCountFlag = false;
            string parentText = "";
            int boolCount = 0;
            DataTable infoTable = new DataTable();
            infoTable = GJPDbHelper.DAL.ExecuteDataSet("SELECT ‘‘ as pinpai,‘‘ as leixing FROM [AIRB_MMTREE] where [treeType] = ‘999‘ ").Tables[0];
 
            foreach (C1TreeViewNode csnode in ctrv.Nodes)
            {
                //csnode.CheckState = C1TreeViewNodeCheckState.Indeterminate;
                if (csnode.CheckState == C1TreeViewNodeCheckState.Checked)
                {
                    if (boolCount > 3)
                    {
                        js.JsAlert("选择油品已大于4个");
                        break;
                    }
                    additemInfoRow(infoTable, csnode.Text, "");
                    boolCount++;
                }
                else if (csnode.CheckState == C1TreeViewNodeCheckState.Indeterminate)
                {
                    foreach (C1TreeViewNode subcsnode in csnode.Nodes)
                    {
                        if (subcsnode.CheckState == C1TreeViewNodeCheckState.Checked)
                        {
                            if (boolCount > 3)
                            {
                                js.JsAlert("选择油品已大于4个");
                                break;
                            }
                            additemInfoRow(infoTable, csnode.Text, subcsnode.Text);
                            boolCount++;
                        }
                    }
                }
            }
            return infoTable;
        }
 
        /// <summary>
        /// 
        /// 快速设置新的结构行
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="level1"></param>
        /// <param name="level2"></param>
        protected void additemInfoRow(DataTable dt, string level1, string level2)
        {
            System.Data.DataRow row;
            row = dt.NewRow();
            // Then add the new row to the collection.
            row[0] = level1;
            row[1] = level2;
            dt.Rows.Add(row);
        }
        //树状图中被选项显示到C1GridView1中
        protected void ButtonToTable_Click(object sender, EventArgs e)
        {
            // 返回目录
            DataTable dt = new DataTable();
            InsusJsUtility js = new InsusJsUtility();
            dt = checkItemTableOil(C1TreeView1);
            int dtCount = dt.Rows.Count;
 
            if (dtCount == 0)
            {
                js.JsAlert("未选择油品!");
            }
            else
            {
                C1GridView1.DataSource = dt;
                C1GridView1.DataBind();
 
                ButtonToDsr.Visible = true;
            }
 
 
        }

以上是关于c# 后台绑定treeview 单个tab的主要内容,如果未能解决你的问题,请参考以下文章

WPF中TreeView控件数据绑定和后台动态添加数据

怎样在treeview中加载数据库 C#

c#怎么用comboBox绑定treeview控件

c# treeview 字体大小

treeview如果根节点下无子节点就不显示此根节点----后台代码该如何写

c# gridview绑定list数据源