利用sharepoint中的的SPgridview展现数据

139 篇文章 1 订阅

利用sharepoint中的的SPgridview展现数据,实现一个类似于sharepoint本身list页的功能

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace SPGridViewDemo
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SPDataSource odsDataSource = new SPDataSource();
odsDataSource.ID = "ExampleSource";
Controls.Add(odsDataSource);

SPSite site = new SPSite("http://bobo-pc");

SPList list = site.RootWeb.GetListFromUrl("http://bobo-pc/Lists/test/AllItems.aspx");

odsDataSource.List = list;


//odsDataSource.FilterExpression

//Response.Write(SPGridView1.ID);
Response.Write(SPGridView1.FilterFieldName);

SPGridView1.FilteredDataSourcePropertyFormat = "{1}='{0}'";
SPGridView1.FilteredDataSourcePropertyName = "FilterExpression";

this.SPGridView1.AutoGenerateColumns = false;
SPGridView1.EnableViewState = false;
// this.SPGridView1.Sorting += new GridViewSortEventHandler(SPGridView1_Sorting);

//if (Page.IsPostBack) return;

// odsDataSource.FilterExpression = this.SPGridView1.FilterFieldName

//SPDataSource mySPDS = new SPDataSource();
//mySPDS.List = taskList;

//添加字段
SPBoundField col = new SPBoundField();
col.DataField = "标题";
col.SortExpression = "标题";
col.HeaderText = "标题";
SPGridView1.Columns.Add(col);

col = new SPBoundField();
col.DataField = "test";
col.SortExpression = "test";
col.HeaderText = "test";
SPGridView1.Columns.Add(col);

//col = new SPBoundField();
//col.DataField = "Rating";
//col.SortExpression = "Rating";
//col.HeaderText = "Rating";
//SPGridView1.Columns.Add(col);
SPGridView1.AllowSorting = true;

SPGridView1.AllowFiltering = true;

SPGridView1.FilterDataFields = ",标题";

//设置分组
SPGridView1.AllowGrouping = false;
SPGridView1.AllowGroupCollapse = true;
SPGridView1.GroupField = "test";
SPGridView1.GroupDescriptionField = "test";
SPGridView1.GroupFieldDisplayName = "分组:";


//添加下拉菜单字段
SPMenuField colMenu = new SPMenuField();
colMenu.HeaderText = "Presenter Name";
colMenu.TextFields = "标题";

//指定关联的菜单ID
colMenu.MenuTemplateId = "PresenterListMenu";
//colMenu.NavigateUrlFields = "标题";
// colMenu.NavigateUrlFormat = "do.aspx?p={0}&q={1}";
//colMenu.TokenNameAndValueFields = "EDIT=Title,NAME=Rating";
//colMenu.SortExpression = "Title";

//菜单
MenuTemplate presenterListMenu = new MenuTemplate();
presenterListMenu.ID = "PresenterListMenu";

//菜单项
MenuItemTemplate biogMenu = new MenuItemTemplate(
"Read Biography", "/_layouts/images/EawfNewUser.gif");
//biogMenu.ClientOnClickNavigateUrl = "do.aspx?this=%EDIT%&that=%NAME%";
biogMenu.ClientOnClickScript = "alert('your javascript here')";
presenterListMenu.Controls.Add(biogMenu);

//菜单项
MenuItemTemplate broadcastMenu = new MenuItemTemplate(
"Recent Broadcasts", "/_layouts/images/ICWM.gif");
presenterListMenu.Controls.Add(broadcastMenu);

//分割线
MenuSeparatorTemplate sepMenu = new MenuSeparatorTemplate();
presenterListMenu.Controls.Add(sepMenu);

//菜单项
MenuItemTemplate favMenu = new MenuItemTemplate(
"Add to Favorites", "/_layouts/images/addtofavorites.gif");
presenterListMenu.Controls.Add(favMenu);

/************************二级菜单项目*****************************/

SubMenuTemplate aaa = new SubMenuTemplate();
aaa.Text = "aaa";
//aaa.Sequence = 400;
aaa.ImageUrl = "/_layouts/images/ICWM.gif";

MenuItemTemplate aaa_1 = new MenuItemTemplate("aaa_1", "/_layouts/images/ICWM.gif");
aaa.Controls.Add(aaa_1);

MenuItemTemplate aaa_2 = new MenuItemTemplate("aaa_2", "/_layouts/images/ICWM.gif");
aaa.Controls.Add(aaa_2);

presenterListMenu.Controls.Add(aaa);
/**********************************************************************/



this.Controls.Add(presenterListMenu);
SPGridView1.Columns.Add(colMenu);

//绑定数据源
this.SPGridView1.DataSourceID = "ExampleSource";
this.SPGridView1.DataBind();
}

public DataTable GetDataTable()
{
DataTable tblData = new DataTable();
tblData.Columns.Add("Title");
tblData.Columns.Add("Author");
tblData.Columns.Add("Rating");

tblData.Rows.Add("Obsession", "Robards, Karen", 2);
tblData.Rows.Add("Vanished", "Robards, Karen", 3);
tblData.Rows.Add("Magician: Apprentice", "Feist, Raymong E.", 4);
tblData.Rows.Add("Magician: Master", "Feist, Raymong E.", 5);
tblData.Rows.Add("Silverthorn", "Feist, Raymong E.", 4);
tblData.Rows.Add("Lord Foul's Bane", "Donaldson, Stephen R.", 3);
tblData.Rows.Add("The Illearth War", "Donaldson, Stephen R.", 4);

return tblData;
}

}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值