PDA

View Full Version : فراخوانی اطلاعات از دیتابیس و ثبت آن در قالب HTML منو(والد و فرزند بصورت treeview)



night-wolf
پنج شنبه 07 دی 1396, 22:36 عصر
با سلام دوستان من یه سری اطلاعات دارم که اونارو بصورت ListNode دریافت کردم به این صورت که اطلاعات پدر و فرزند که تو دیتابیس مشخصه میخوام بصورت مرتب زیر والد خودش قرار بگیره اینم کدکلاسش

public ListNodes getNode(string UserTypeGuid, int status)
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrin gs["ConStrings"].ConnectionString);
try
{
using (SqlCommand command = new SqlCommand("SelectAllNodes", connection))
{
command.Parameters.AddWithValue("@UserTypeGuid", UserTypeGuid);
command.Parameters.AddWithValue("@status", status);
command.CommandType = CommandType.StoredProcedure;

if (connection.State == ConnectionState.Closed)
connection.Open();

ListNodes list = new ListNodes();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Node temp = new Node();
temp.IDNode = new Guid(reader["IDNode"].ToString());
temp.ParentNodeID = new Guid(reader["ParentNodeID"].ToString());
temp.NodeName = reader["NodeName"].ToString();
temp.NodeCaption = reader["NodeCaption"].ToString();
temp.Periority = Int32.Parse(reader["Periority"].ToString());
temp.NavigateUrl = reader["NavigateUrl"].ToString();
temp.UserTypeID = reader["UserTypeID"].ToString();
//temp.Tni = reader["tni"].ToString();
//temp.Security = reader["Security"].ToString();
temp.Status = (int)reader["Status"];
list.Add(temp);
}
reader.Close();
}
command.Dispose();
return list;
}
}
catch (Exception exp)
{ return null; }
finally { connection.Close(); }
}


و اینم کد فراخوانیش در فرم

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Common_Layer;

public partial class _Default : System.Web.UI.Page
{

private ListNodes AllNodes;
public void BindTreeNode(Guid ParentID, TreeNode node)
{
GetNodes getnode = new GetNodes();
for (int idx = 0; idx < AllNodes.Count; idx++)
{
if (AllNodes[idx].ParentNodeID == ParentID)
{
TreeNode TempNode = new TreeNode();
TempNode.Text = AllNodes[idx].NodeCaption;
TempNode.Value = AllNodes[idx].IDNode.ToString();
TempNode.CollapseAll();
if (AllNodes[idx].NavigateUrl.ToString() != "")
TempNode.NavigateUrl = AllNodes[idx].NavigateUrl;
node.ChildNodes.Add(TempNode);
if (HaveChild(TempNode))
BindTreeNode(new Guid(TempNode.Value), TempNode);
}
}
}
private bool HaveChild(TreeNode node)
{
bool havechild = false;
for (int idx = 0; idx < AllNodes.Count; idx++)
{
if (AllNodes[idx].IDNode == new Guid(node.Value))
havechild = true;
}
return havechild;
}

protected void Page_Load(object sender, EventArgs e)
{
GetNodes method = new GetNodes();
AllNodes = method.getNode("{48401D4A-2F90-469E-849B-FBFD6F044AA1}", 0);

}
}حالا من چیکار کنم که اطلاعات والد در قالب html ست بشه


<ul class="sidebar-menu" data-widget="tree">

<li class="active treeview">
<a href="لینک والد">
<i class="fa fa-dashboard"></i> <span>عنوان والد</span>
<span class="pull-left-container">
<i class="fa fa-angle-right pull-left"></i>
</span>
</a>
<ul class="treeview-menu">
<li class="active"><a href="لینک زیرمنو یا فرزند اول"><i class="fa fa-circle-o"></i> عنوان زیرمنویا فرزند اول </a></li>
<li><a href="لینک فرزند دوم"><i class="fa fa-circle-o"></i> عنوان فرزند دوم</a></li>
</ul>


خیلی ممنون

EnKamran
دوشنبه 11 دی 1396, 12:09 عصر
سلام دوست عزیز.
اول : حتما باید از نودلیست استفاده كنید؟
دوم: موارد شما تودرتو نامحدود هستند یا یك لولی؟
اگر فقط یه لول دارید كه كار ساده میشود با ریپیتر همی میتوانید انجام دهید
در غیر این صورت میتوانید از توابع بازگشتی استفاده كنید و كدهای اچ تی ام ال رو در كدبیهایند جنریت كنید و در یك لیترال یا لیبل نمایش بدید.
تو سایت amozesh.net مقاله ای در این رابطه نوشته بودم میتوانید جست و جوكنید "منو تودرتو دردات نت"