我在我的SharePoint網站中名爲「Empdetails」並具有列(EmpName字符串,Empaddress字符串)的列表。使用Webparts在Sharepoint 2010的SPgridview中編輯,刪除和更新操作
我必須將列表數據與編輯,刪除,更新功能綁定到SpGridview。
我能夠將列表數據綁定到gridview成功,但我無法提供編輯,刪除,更新功能到gridview。
代碼:
private void binddata()
{
SPWeb mySite = SPContext.Current.Web;
SPList myList = mySite.Lists["Empdetails"];
SPListItemCollection items = myList.Items;
//Here we will make a datatable and we will put our list data to the data table
DataTable table=new DataTable();
table.Columns.Add("EmpName", typeof(string));
table.Columns.Add("Empaddress", typeof(string));
// Create rows for each splistitem
DataRow row;
foreach (SPListItem result in items)
{
row = table.Rows.Add();
row["EmpName"] = result["EmpName"].ToString();
row["Empaddress"] = result["Empaddress"].ToString();
}
//binding data to gridview
GridView1.DataSource = table.DefaultView;
GridView1.DataBind();
}
感謝我們的代碼。但我需要的任何引用鏈接進行了解,以實現我的任務......我知道,這不是自動提供的...這就是易張貼了這個問題。 – user1716577
在這種情況下,您需要提出更具體的問題。 Stackoverflow是爲了問題和答案,而不是爲你寫你的項目。 –
我不需要完整的代碼。我只需要指導如何在gridview中實現curd操作。這就是爲什麼我在堆棧溢出中發佈這個問題。 – user1716577