Diễn đàn    ASP.NET & Sharepoint MOSS, WSS 2007    Truy xuất 1 cái list trong SharePoint

Thành viênTrả lời
quangvd


102  bài
24-9-2010 22:27:31
using System.Data;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace GetCustomerWP
{
[Guid("8e91c8ff-be34-4ba3-8b1b-8a80e2128d9b")]
public class GetCustomerWP : System.Web.UI.WebControls.WebParts.WebPart
{
GridView gvCustomer;
public GetCustomerWP()
{
this.ExportMode = WebPartExportMode.All;
}

protected override void CreateChildControls()
{
base.CreateChildControls();
DataTable table = new DataTable("Customers");
table.Columns.Add("TenKhach", typeof(string));
table.Columns.Add("Amount", typeof(int));

using (SPWeb oWeb = SPContext.Current.Web)
{
SPList oList = oWeb.Lists["Customers"];
SPListItemCollection oItems = oList.Items;
foreach (SPListItem item in oItems)
{
DataRow row = table.NewRow();
row["TenKhach"] = item["Title"].ToString();
row["Amount"] = item["Amount"].ToString();
table.Rows.Add(row);

}

}
gvCustomer = new GridView();
gvCustomer.DataSource = table;
gvCustomer.DataBind();
this.Controls.Add(gvCustomer);


}


}
}

Cái này để truy cập vào list có tên là customers
Các bạn có thể dùng CAML để truy xuất dữ liệu có điều kiện trong list Pages của SharePoint. Có thể dùng cái này để làm danh sách bài viết trong SharePoint Portal
 
aspnet

Lập trình không biên giới
608  bài
28-9-2010 11:1:58
Hay , hay quá
---
Coding for food
http://yenbai.awas.vn
http://tknd.vn
http://coder.awas.vn
http://awas.vn
http://bieuquyet.vn
http://webhocsinh.com
 
mrhackga


5  bài
21-10-2010 1:26:4
Không biết về cái này ,mong chỉ giáo
 

Chủ đề gần đây :

Cùng loại :

Tên file Mô tả chi tiết Ngày
NWeb.zip (1) Module đơn giản Newsweb trên Dotnetnuke v10.x.x.x10/18/2025 8:08:11 AM
vspforum.zip (11) Ma nguon vspforum ngay xua4/18/2023 6:38:37 AM
pdfjs.rar (2) pdfjs 2017 : hiển thị tốt trên iphone 11, 12, 13 không lỗi, bản 2012 sẽ lỗi trên iphone6/21/2022 11:52:48 AM
pdfjs2.rar (2) Xem file pdf bằng viewer.hml cua pdfjs (thư viện chuẩn mozilla) 2012. https://mozilla.github.io/pdf.js/getting_started/#download có thể download bản prebuild tại đây6/21/2022 11:52:04 AM
runner.zip (0) using three.js, orbitcontrol to view an object move random on map. Di chuyển 1 đồ vật ngẫu nhiên trên bản đồ, sử dụng với demo nhân viên di chuyển trong văn phòng. Toàn js download về là chạy12/5/2019 5:55:14 PM
gmap.zip (1) google map + marker7/17/2019 2:25:05 PM
vinsmarthomeservice.zip (1) java post json to api, use AsyncTask, event listener7/9/2019 5:00:10 PM
fblogin.zip (0) Login facebook bang javascript SDK7/9/2019 9:16:37 AM
autocomplete-location.zip (2) autocomplete location geo from google place, html + js7/4/2019 4:37:55 PM
WebAPI.zip (8) api for android access db (v1.0.0)7/4/2019 9:14:17 AM