Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Sharepoint 2010中的快速午餐定制_Javascript_Asp.net_C# 4.0_Sharepoint 2010_Web Parts - Fatal编程技术网

Javascript Sharepoint 2010中的快速午餐定制

Javascript Sharepoint 2010中的快速午餐定制,javascript,asp.net,c#-4.0,sharepoint-2010,web-parts,Javascript,Asp.net,C# 4.0,Sharepoint 2010,Web Parts,我创建了一个web部件“自定义快速午餐”,可以在sharePoint 2010中展开和收拢(+和-),问题是当加载网站时,快速午餐的默认值被展开,我希望它被收拢,我不知道怎么做 你能帮帮我吗 第一个代码是用户控件的c代码 using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint; u

我创建了一个web部件“自定义快速午餐”,可以在sharePoint 2010中展开和收拢(+和-),问题是当加载网站时,快速午餐的默认值被展开,我希望它被收拢,我不知道怎么做 你能帮帮我吗

第一个代码是用户控件的c代码

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;

namespace QuickLaunchWebpart.Quicklaunch_Webpart
{
public partial class Quicklaunch_WebpartUserControl : UserControl
{
    private void LoadQuickLauchDesign()
    {
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {

                Guid SiteID = SPContext.Current.Site.ID;
                Guid WebID = SPContext.Current.Web.ID;

                using (SPSite site = new SPSite(SiteID))
                {
                    using (SPWeb web = site.OpenWeb(WebID))
                    {
                        SPUser oUser = SPContext.Current.Web.CurrentUser;
                        SPNavigationNodeCollection nodecoll = web.Navigation.QuickLaunch;
                        foreach (SPNavigationNode node in nodecoll)
                        {
                            TableRow tr = new TableRow();
                            TableCell cell = new TableCell();
                            cell.Style.Add("padding-bottom", "15px");

                            Table innerTable = new Table();
                            innerTable.CellPadding = 0;
                            innerTable.CellSpacing = 0;
                            //  innerTable.BorderWidth = 1;
                            innerTable.Style.Add("width", "100%");
                            TableRow innerTrTitle = new TableRow();
                            innerTrTitle.Attributes.Add("onclick", "category_click()");
                            TableCell innerCellTitle = new TableCell();
                            innerCellTitle.CssClass = "category";

                            Image img = new Image();
                            img.ImageAlign = ImageAlign.Left;
                            img.ImageUrl = "/_layouts/images/MDNExpanded.png";
                            Label title = new Label();
                            title.Style.Add("font-size", "larger");
                            title.Text = node.Title;


                            Table titleCellTable = new Table();
                            titleCellTable.CellPadding = 0;
                            titleCellTable.CellSpacing = 0;
                            //titleCellTable.Attributes.Add("border", "1"); 
                            TableRow trtitleCellTable = new TableRow();
                            TableCell imageCell = new TableCell();
                            TableCell titleCell = new TableCell();
                            imageCell.Controls.Add(img);
                            titleCell.Controls.Add(title);
                            trtitleCellTable.Cells.Add(imageCell);
                            trtitleCellTable.Cells.Add(titleCell);
                            titleCellTable.Rows.Add(trtitleCellTable);


                            innerCellTitle.Controls.Add(titleCellTable);
                            innerTrTitle.Cells.Add(innerCellTitle);
                            innerTable.Rows.Add(innerTrTitle);

                            Panel div = new Panel();
                            div.Style.Add("background-color", "#FCFCFC");
                            //div.Style.Add("border-left", "1px solid #DBDDDE");
                            //div.Style.Add("border-bottom", "1px solid #DBDDDE");
                            Table childTable = new Table();
                            childTable.CellPadding = 0;
                            childTable.CellSpacing = 0;

                            childTable.Style.Add("width", "100%");

                            foreach (SPNavigationNode childnode in node.Children)
                            {
                                childTable.Rows.Add(ChildTableRow(childnode.Title, childnode.Url));
                            }
                            div.Controls.Add(childTable);

                            TableRow innerTrLinks = new TableRow();
                            innerTrLinks.Visible = true;
                            TableCell innerCellLinks = new TableCell();
                            innerCellLinks.Style.Add("border-right", "1px solid #DBDDDE");
                            innerCellLinks.Style.Add("padding-left", "15px");

                            innerCellLinks.Controls.Add(div);
                            innerTrLinks.Cells.Add(innerCellLinks);
                            innerTable.Rows.Add(innerTrLinks);

                            cell.Controls.Add(innerTable);
                            tr.Cells.Add(cell);
                            tbl1.Rows.Add(tr);
                        }
                    }
                }
            });
        }
        catch (Exception ex)
        {
            lblError.Text = ex.StackTrace;
            lblError.Visible = true;
        }
    }

    private TableRow ChildTableRow(string title, string Url)
    {
        TableRow tr = new TableRow();
        tr.Height = 20;
        TableCell cell = new TableCell();
        HyperLink link = new HyperLink();
        link.Text = title;
        link.NavigateUrl = Url;
        link.Attributes.Add("quick_link", "true");
        link.Style.Add("display", "block");
        cell.Controls.Add(link);
        tr.Cells.Add(cell);

        if (Request.Url.ToString().Contains(Url) && !(Request.Url.ToString().Contains("/SitePages/Home.aspx")))
        {
            tr.Attributes.Add("current", "true");
            link.Attributes.Add("current", "true");
        }

        return tr;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadQuickLauchDesign();

    }
}
}
以下代码用于usercontrol中使用的java脚本

<script type="text/javascript">

function category_click() {

    var evtSource = event.srcElement + '';
    var innerTblRef = null;

    if (evtSource == '[object HTMLTableCellElement]') {
        innerTblRef = event.srcElement.parentElement.parentElement;
    } else if (evtSource == '[object HTMLSpanElement]' || evtSource == '[object HTMLImageElement]') {
        innerTblRef = event.srcElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
    }

    //Locating the Collapse Image icon
    var imgRef = innerTblRef.rows[0].cells[0].firstChild.rows[0].cells[0].firstChild

    if (innerTblRef.rows[1].style.visibility == 'visible' || innerTblRef.rows[1].style.visibility == '') {
        innerTblRef.rows[1].style.visibility = 'hidden';
        innerTblRef.rows[1].style.display = 'none';
        imgRef.src = "/_layouts/images/MDNCollapsed.png";
    } else {
        innerTblRef.rows[1].style.visibility = 'visible';
        innerTblRef.rows[1].style.display = 'block';
        imgRef.src = "/_layouts/images/MDNExpanded.png";
    }
}

function link_hover() {
    var cellRef = event.srcElement;
    cellRef.className = "link_hover";

    if (cellRef + '' == '[object HTMLTableCellElement]') {      //Cell hover
        cellRef.firstChild.className = "link_hover";

    } else {        // Image hover
        cellRef.parentElement.className = "link_hover";
    }
}

function link_hout() {
    var cellRef = event.srcElement;
    cellRef.className = "link_hout";

    if (cellRef + '' == '[object HTMLTableCellElement]') {      //Cell hover
        cellRef.firstChild.className = "link_hout";

    } else {        // Image hover
        cellRef.parentElement.className = "link_hout";
    }
}

</script>

功能类别\u单击(){
var evtSource=event.src元素+“”;
var innerTblRef=null;
如果(evtSource=='[object HTMLTableCellElement]'){
innerTblRef=event.srcElement.parentElement.parentElement;
}else if(evtSource=='[object HTMLSpanElement]'| | evtSource=='[object HTMLImageElement]'){
innerTblRef=event.srcElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
}
//定位折叠图像图标
var imgRef=innerTblRef.rows[0]。单元格[0]。firstChild.rows[0]。单元格[0]。firstChild
如果(innerTblRef.rows[1].style.visibility=='visible'| | innerTblRef.rows[1].style.visibility==''){
innerTblRef.rows[1].style.visibility='hidden';
innerTblRef.rows[1].style.display='none';
imgRef.src=“/_layouts/images/MDNCollapsed.png”;
}否则{
innerTblRef.rows[1].style.visibility='visible';
innerTblRef.rows[1].style.display='block';
imgRef.src=“/_layouts/images/MDNExpanded.png”;
}
}
函数链接_hover(){
var cellRef=event.src元素;
cellRef.className=“链接悬停”;
如果(cellRef+''='[object HTMLTableCellElement]'){//单元格悬停
cellRef.firstChild.className=“link\u hover”;
}否则{//图像悬停
cellRef.parentElement.className=“link\u hover”;
}
}
函数链接_hout(){
var cellRef=event.src元素;
cellRef.className=“link\u hout”;
如果(cellRef+''='[object HTMLTableCellElement]'){//单元格悬停
cellRef.firstChild.className=“link\u hout”;
}否则{//图像悬停
cellRef.parentElement.className=“link\u hout”;
}
}

你能帮我吗?

我在朋友的帮助下解决了问题,在LoadQuickLauchDesign中添加了以下行

if(node.Children.Count>0) img.ImageUrl="/_layouts/images/MDNCollapsed.png"
else img.ImageUrl = "/_layouts/images/MDNExpanded.png";
而不是

img.ImageUrl = "/_layouts/images/MDNExpanded.png";
并在ChildTableRow函数中添加以下内容 innerTrLinks.Style.Add(“显示”、“无”); 添加(“可见性”、“隐藏”); 而不是 innerTrLinks.Visible=true; 它将完美地工作