我的 SharePoint 网站中有一个列表,名称为“Empdetails”并包含列(EmpName 字符串、Empaddress 字符串)。
我必须使用编辑、删除、更新功能将列表数据绑定到 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();
}