2010-05-10 24 views
0

我不會創建一個具有編輯總部設在GridView的用戶控件添加刪除一體化, 問題是這些:創建ASP.NET GridView的通用

在我的網站的管理部分我必須重複視圖相同的動作添加刪除更新不同數據源的數據。

我不會創建一個包含這些操作的泛型gridview。

該gridview可以採取一個XML文件,配置他自我依賴於desplay的數據請求。

任何想法我可以做到這一點?

回答

1

標準gridview使您可以添加刪除和更新功能,你正在尋找。如果您想要執行額外的操作(例如添加,刪除和更新到其他數據源),則標準GridView具有啓用該操作的事件。

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events.aspx

請看下面的事件處理程序的GridViewUpdatedEventArgs參數。它包含數據鍵,OldValues和NewValues。您需要記錄您的更改或將其複製到其他數據源中的所有內容。

protected void CustomersGridView_RowUpdated(Object sender, GridViewUpdatedEventArgs e) 
{ 

if(e.Exception == null) 
{ 
    //Perform your additional update to your other datasource here 


} 
else 
{ 
    e.ExceptionHandled = true; 
    Message.Text = "An error occurred while attempting to update the row."; 
} 

}