c# 后台绑定treeview 单个tab

时间:2021-11-24 04:54:11

<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;             }         }