How can I export a GridView.DataSource to a datatable or dataset?

后端 未结 7 1122
心在旅途
心在旅途 2020-11-28 08:45

How can I export GridView.DataSource to datatable or dataset?

相关标签:
7条回答
  • 2020-11-28 09:20

    If you do gridview.bind() at:

    if(!IsPostBack)
    
    {
    
    //your gridview bind code here...
    
    }
    

    Then you can use DataTable dt = Gridview1.DataSource as DataTable; in function to retrieve datatable.

    But I bind the datatable to gridview when i click button, and recording to Microsoft document:

    HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests.

    If you have same condition, then i will recommend you to use Session to persist the value.

    Session["oldData"]=Gridview1.DataSource;
    

    After that you can recall the value when the page postback again.

    DataTable dt=(DataTable)Session["oldData"];
    

    References: https://msdn.microsoft.com/en-us/library/ms178581(v=vs.110).aspx#Anchor_0

    https://www.c-sharpcorner.com/UploadFile/225740/introduction-of-session-in-Asp-Net/

    0 讨论(0)
提交回复
热议问题