获取sharepoint列表的可用视图并填充到下拉列表中?

时间:2013-01-25 12:53:18

标签: asp.net c#-4.0 sharepoint-2010

             1. Here the sample code i tried for getting the available views for the
                sharepoint list and populating into the dropdownlist

          protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    SPSite site = new SPSite(SPContext.Current.Site.Url);
                    foreach (SPWeb web in site.AllWebs)
                    {
                        SPListCollection spListCollection = web.GetListsOfType(SPBaseType.GenericList);

                        foreach (SPList splist in spListCollection)
                        {
                            ListNameList.Items.Add(splist.Title.ToString());                        
                        }
                        ListNameList.Items.Insert(0, "--Select--");

                    }
                }
}

                       protected void ListNameList_SelectedIndexChanged(object sender,EventArgs e)
                           {
                            SPSite site = new SPSite(SPContext.Current.Site.Url);
                            SPWeb web = site.OpenWeb();
                            SPList selectedlist = web.Lists[ListNameList.SelectedValue];
                            foreach (SPView views in selectedlist.Views)
                            {
                                ViewNameList.Items.Add(views.Views.ToString());
                            }
                          }
  1. 我在sharepoint列表中创建了视图,但是在上面的代码中 循环时,我得到了正确的视图名称,但填入时 下拉列表我得到的输出像Microsoft.Sharepoint 观点名称。

        Can you help me out of this?
    

1 个答案:

答案 0 :(得分:0)

我认为您只需要编辑在新项目中添加到ViewNameList的行以使用view.Title

protected void ListNameList_SelectedIndexChanged(object sender,EventArgs e)
{
    SPSite site = new SPSite(SPContext.Current.Site.Url);
    SPWeb web = site.OpenWeb();
    SPList selectedlist = web.Lists[ListNameList.SelectedValue];
    foreach (SPView views in selectedlist.Views)
    {
        ViewNameList.Items.Add(views.Title);
    }
}

如果集合没有按照您想要的顺序返回,也可能需要对视图进行排序。