如何在sharePoint 2010中的Gridview中显示列表值 [英] How to show List Values in Gridview in sharePoint 2010

查看:85
本文介绍了如何在sharePoint 2010中的Gridview中显示列表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

存在与SharePoint服务器相关的问题.其实我的问题是.我在VS 2010中添加了一个SharePoint 2010空项目,并添加了一个应用程序页面.在应用程序page.aspx.cs中,我为网格视图编写了代码.我在SharePoint Server 2010中创建了一个列表,其中有些列假设名称",这些值是AbC. CSE等.

然后我的问题是,我想在网格视图"中显示列表的名称"列的值".当我们运行程序时,那么我在应用程序"页面中编写了什么代码.

示例:我的列表名称为"MyList",其中有一个名称"列,其中有一些值
并在应用页面中添加了网格视图代码.
部署页面时,名称"值显示为网格视图".



很多Thnx,
Sumit魔术师.

Hi frends,

There is issue related to SharePoint server. Actually my issue is that. I added one empty project of SharePoint 2010 in VS 2010 and add a application page. In application page.aspx.cs I write the code for a grid view. and I create a List in SharePoint Server 2010 there are some columns suppose "Name" and these values is AbC. CSE etc.

Then my issue is that, I Want to show the" values of ''Name'' Column of List" in Grid View. when we run the program, So what code I write in Application page.

Example : My list Name is "MyList" there is one Name Column and some values is there
and in added a grid view code in app page.
when deploy the page the Name values shows is Grid View.



A lot of Thnx,
Sumit Magician.

推荐答案

Sumit,

在这里,我为您提供用于访问共享点列表和检索数据的代码.您必须将检索到的数据添加到数据网格中.

//SPSite对象
SPSite oSpSite =新的SPSite("http://spserver:2222/");//您的服务器


//创建SPWeb对象以打开Web.
//使用SPWeb对象连接到Web
SPWeb oSPWeb = oSpSite.OpenWeb();


//创建SPList对象以访问列表.
//这里,我们需要传递要从Sharepoint网站访问的列表名称.
//List对象从共享点站点获取列表
SPList oSpList = oSPWeb.Lists ["MyList"];


//创建SPListItemCollection以获取所有列表项.
//获取所有物品的物品集合对象形成列表
SPListItemCollection oSpListCln = oSpList.Items;


//遍历ItemCollection对象中的每个项目.
//遍历itemcollection对象中的所有项目
foreach(oSpListCln中的SPListItem项)
{
字符串名称= item [名称"];

//在此处编写代码以将列表数据值添加到Gridview

}
Hi Sumit,

Here I''m giving you the code for access your sharepoint list and the retrive data. You have to add the retrieved data to the data grid.

//SPSite object
SPSite oSpSite = new SPSite("http://spserver:2222/");// Your server


// Create SPWeb Object to open the Web.
//Connect to the web using SPWeb object
SPWeb oSPWeb = oSpSite.OpenWeb();


// Create SPList object to access the List.
//Here we need to pass List Name which we want to access from Sharepoint site.
//List Object to get the list from a sharepoint site
SPList oSpList = oSPWeb.Lists["MyList"];


//Create SPListItemCollection to get all the list items.
//Item Collection Object getting all the items form the list
SPListItemCollection oSpListCln = oSpList.Items;


//Iterate through each and every item in the ItemCollection object.
//iterate through all the items in itemcollection object
foreach (SPListItem item in oSpListCln)
{
string name =item["Name"];

//In here write a code for add the list data values to the Gridview

}


这篇关于如何在sharePoint 2010中的Gridview中显示列表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆