Veb-qismga TreeView boshqaruv elementlarini qo'shish
Ushbu vazifada TreeView boshqaruvi veb-qismning dizayn yuzasiga qo'shiladi. TreeView boshqaruvi ro'yxatlar va quyi saytlarning ierarxik ko'rinishini ko'rsatadi.
Solution Explorer-da Visual Web Part1 tugunini kengaytiring, Visual Web Part1 User Control.ascx faylini o'ng tugmasini bosing va Конструктор представлений-ni tanlang. Boshqaruv elementlarini asboblar panelidan veb-qismni loyihalash maydoniga sudrab olib borish uchun ko'rinish ochiladi.
Ekranning chap tomonidagi asboblar panelida Navigatsiya bo'limini bosing va TreeView boshqaruvini dizayn maydoniga torting. Agar asboblar paneli ekranning chap tomonida ko'rsatilmasa, Ko'rish menyusida Asboblar panelini bosing.
TreeView boshqaruvini tanlang va Visual Studio ekranining pastki o'ng burchagidagi xususiyatlar panelida Code maydoniga siteStructure nomini kiriting.
Loyihaga kod qo'shish
Ushbu vazifada siz SharePoint saytidagi barcha roʻyxatlar va quyi saytlar boʻylab takrorlanadigan va ularni TreeView boshqaruviga qoʻshadigan Microsoft Visual C# kodini loyihangizga qoʻshasiz.
Solution Explorer-da Visual Web Part1 User Control.ascx tugunini kengaytiring, Visual Web Part1 User Control.ascx.cs tugunini o'ng tugmasini bosing va Kodni ko'rish-ni tanlang.
Ekrandagi kodni quyidagi C# kodi bilan almashtiring.
C#Copy
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities; using System.Web;
namespace BonnevilleTestBed.Bonneville
{
public partial class BonnevilleUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb thisWeb = null; TreeNode node;
thisWeb = SPContext.Current.Web;
//Add the Web's title as the display text for the tree node, and add the URL as the NavigateUri.
node = new TreeNode(thisWeb.Title, null, null, thisWeb.Url, "_self");
//The Visual Web Part has a treeview control called siteStructure. siteStructure.Nodes.Add(node);
//Get a reference to the current node, so child nodes can be added in the correct position.
TreeNode parentNode = node;
//Iterate through the Lists collection of the Web. foreach (SPList list in thisWeb.Lists)
{
if (!list.Hidden)
{
node = new TreeNode(list.Title, null, null, list.DefaultViewUrl, "_self"); parentNode.ChildNodes.Add(node);
}
}
foreach (SPWeb childWeb in thisWeb.Webs)
{
//Call our own helper function for adding each child Web to the tree. addWebs(childWeb, parentNode);
childWeb.Dispose();
}
siteStructure.CollapseAll();
}
void addWebs(SPWeb web, TreeNode parentNode)
{
TreeNode node;
node = new TreeNode(web.Title, null, null, web.Url, "_self"); parentNode.ChildNodes.Add(node);
parentNode = node;
foreach (SPList list in web.Lists)
{
if (!list.Hidden)
{
node = new TreeNode(list.Title, null, null, list.DefaultViewUrl, "_self"); parentNode.ChildNodes.Add(node);
}
}
foreach (SPWeb childWeb in web.Webs)
{
//Call the addWebs() function from itself (i.e. recursively)
//to add all child Webs until there are no more to add. addWebs(childWeb, parentNode); childWeb.Dispose();
}
}
}
}
Do'stlaringiz bilan baham: |