/// <summary> /// 树的数据绑定,1张表,上级-1; /// </summary> /// <param name="TView"></param> /// <param name="node"></param> /// <param name="id"></param> /// <param name="DataTable"></param> /// <param name="ParentGuid"></param> /// <param name="MenuGuid"></param> /// <param name="MenuName"></param> /// <param name="ConnetionString"></param> public void AddNodes(TreeView TView, TreeNode node, string PidValue, string DataTable, string ParentGuid, string MenuGuid, string MenuName, string StrCondition, string OrderField, string SessionID) { try { sql = ControlDataBindSql.AddNodesSql(DataTable, ParentGuid, PidValue, StrCondition, OrderField); DataSet ds = db.GetDataSet(sql); DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) //循环子节点集合 { TreeNode nd = new TreeNode(); nd.Value = dr[MenuGuid].ToString(); //存放节点 ID nd.Text = dr[MenuName].ToString(); //设置节点名称// if (node == null || PidValue == "-1") { TView.Nodes.Add(nd); //添加至根节点 } else { node.ChildNodes.Add(nd); //添加子节点 } AddNodes(TView, nd, nd.Value, DataTable, ParentGuid, MenuGuid, MenuName, StrCondition, OrderField, SessionID); //递归,添加该节点的子节点 } } catch (Exception Err) { ErrorLog.LogInsert(Err.Message, "ControlDataBind", SessionID); } }
//树的数据绑定,2张表 public void AddPNodes(TreeView TView, TreeNode node, string PDataTable, string PMenuGuid, string PMenuName, string PMenuUrl, string PStrCondition, string SDataTable, string SMenuGuid, string SMenuName, string SMenuUrl, string SStrCondition, string ConParentGuid, string OrderField, string SessionID) { try { TView.Nodes.Clear(); sql = ControlDataBindSql.AddPNodesSql(PDataTable, PStrCondition, OrderField); DataTable dt = db.GetDataTable(sql); foreach (DataRow dr in dt.Rows) //循环子节点集合 { TreeNode nd = new TreeNode(); nd.Value = dr[PMenuGuid].ToString(); //存放节点 ID nd.Text = dr[PMenuName].ToString(); //设置节点名称 nd.Target = "QuestionMain"; nd.ImageUrl = "../images/Group.gif"; nd.NavigateUrl = PMenuUrl + "?" + PMenuGuid + "=" + dr[PMenuGuid].ToString(); TView.Nodes.Add(nd); //添加至根节点 AddSNodes(TView, nd, nd.Value, SDataTable, ConParentGuid, SMenuGuid, SMenuName, SMenuUrl, SStrCondition, OrderField, SessionID); //递归,添加该节点的子节点 } TView.DataBind(); } catch (Exception Err) { ErrorLog.LogInsert(Err.Message, "ControlDataBind", SessionID); } }
/// <summary> /// 知识树/文章列表 /// </summary> /// <param name="TView"></param> /// <param name="node"></param> /// <param name="PidValue"></param> /// <param name="DataTable"></param> /// <param name="ParentGuid"></param> /// <param name="MenuGuid"></param> /// <param name="MenuName"></param> /// <param name="StrCondition"></param> /// <param name="OrderField"></param> /// <param name="SessionID"></param> public void AddNodesArticle(TreeView TView, TreeNode node, string PidValue, string DataTable, string ParentGuid, string MenuGuid, string MenuName, string StrCondition, string OrderField, string SessionID) { try { if (node != null && PidValue != "-1") { sql = ControlDataBindSql.AddArticleSql(PidValue); DataSet ds1 = db.GetDataSet(sql); if (ds1.Tables[0].Rows.Count > 0) { for (int i = 0; i <= ds1.Tables[0].Rows.Count - 1; i++) { TreeNode nd1 = new TreeNode(); //nd1.ShowCheckBox = true; nd1.Text = ds1.Tables[0].Rows[i]["ArticleTitle"].ToString(); nd1.Value = ds1.Tables[0].Rows[i]["KBaseArticle_Guid"].ToString(); //nd1.ImageUrl = "../images/folder.gif"; node.ChildNodes.Add(nd1); } } } sql = ControlDataBindSql.AddNodesSql(DataTable, ParentGuid, PidValue, StrCondition, OrderField); DataSet ds = db.GetDataSet(sql); if (ds.Tables[0].Rows.Count > 0) { DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) //循环子节点集合 { TreeNode nd = new TreeNode(); nd.Value = dr[MenuGuid].ToString(); //存放节点 ID nd.Text = dr[MenuName].ToString(); //设置节点名称 nd.ImageUrl = "../images/folder.gif"; //图像Url nd.NavigateUrl = "#"; if (node == null || PidValue == "-1") { TView.Nodes.Add(nd); //添加至根节点 } else { node.ChildNodes.Add(nd); //添加子节点 } AddNodesArticle(TView, nd, nd.Value, DataTable, ParentGuid, MenuGuid, MenuName, StrCondition, OrderField, SessionID); //递归,添加该节点的子节点 } } } catch (Exception Err) { ErrorLog.LogInsert(Err.Message, "CS/ControlDataBind", SessionID); } }
/// <summary> /// 下拉列表数据绑定 /// </summary> /// <param name="DDList">绑定控件名称</param> /// <param name="DataName">绑定字段名称</param> /// <param name="DataId">班定字段Id</param> /// <param name="Type">绑定的类型 1为带有"请选择", 2为没有"请选择",3"请选择"的值为空</param> public bool DropDownListBind(DropDownList DDList, string DataTable, string DataName, string DataId, int Type, string StrCondition, string SessionID) { try { sql = ControlDataBindSql.DropDownListBindSql(DataTable, DataName, DataId, StrCondition); DataTable dt = db.GetDataTable(sql); DataRow dr = null; if (Type == 1) { dr = dt.NewRow(); dr[DataName] = "请选择"; dr[DataId] = "-1"; dt.Rows.InsertAt(dr, 0); } else if (Type == 0) { dr = dt.NewRow(); dr[DataName] = ""; dr[DataId] = "-1"; dt.Rows.InsertAt(dr, 0); } else if (Type == 3) { dr = dt.NewRow(); dr[DataName] = "请选择"; dr[DataId] = ""; dt.Rows.InsertAt(dr, 0); } else if (Type == 4) { dr = dt.NewRow(); dr[DataName] = "0"; dr[DataId] = "0"; dt.Rows.InsertAt(dr, 0); } DDList.DataSource = dt; DDList.DataTextField = DataName; DDList.DataValueField = DataId; DDList.DataBind(); return(true); } catch (Exception Err) { ErrorLog.LogInsert(Err.Message, "CS/ControlDataBind", SessionID); return(false); } }
//树的数据绑定,2张表,子菜单 private void AddSNodes(TreeView TView, TreeNode node, string ParentValue, string SDataTable, string ConParentGuid, string SMenuGuid, string SMenuName, string SMenuUrl, string SStrCondition, string OrderField, string SessionID) { try { sql = ControlDataBindSql.AddNodesSql(SDataTable, ConParentGuid, ParentValue, SStrCondition, OrderField); DataTable dt = db.GetDataTable(sql); foreach (DataRow dr in dt.Rows) //循环子节点集合 { TreeNode nd = new TreeNode(); nd.Value = dr[SMenuGuid].ToString(); //存放节点 ID nd.Text = dr[SMenuName].ToString(); //设置节点名称 nd.Target = "QuestionMain"; nd.NavigateUrl = SMenuUrl + "?" + SMenuGuid + "=" + dr[SMenuGuid].ToString(); node.ChildNodes.Add(nd); //添加子节点 } } catch (Exception Err) { ErrorLog.LogInsert(Err.Message, "ControlDataBind", SessionID); } }