How to take the backup of gridview data.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • btreddy
    New Member
    • Oct 2008
    • 83

    How to take the backup of gridview data.

    Hii Experts,

    I've a query about gridview.

    My requirement is, in one of my webpages there is one gridview which is displaying the participants data like name ,emilid and so on.if the user wants he can edit the values and update the same in the database also..but before he is commiting the changes to the database i wanna to take the back up of those pervious values(before modifying ).

    i tried of reading the cell values in the RowDataBound event of the gridview but it didn work for me ..getting all as null values only.

    Can somebody tell me how can i do this.

    Thank you
    Rgds,
    BTR.
  • shrimant
    New Member
    • Sep 2007
    • 48

    #2
    Modify the following piece of code to fit your requirement, it saves the Gridview contents to an Excel. Id you have sorting or Paging or other customization.. .as you see below you need to turn them off before you could save the entire content. There is also an restriction of Max 65536 rows...due to excel.

    Code:
    Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
            If GridView1.Rows.Count.ToString + 1 < 65536 Then
                GridView1.AllowPaging = False
                GridView1.AllowSorting = False
                GridView1.DataBind()
                Dim tw As New StringWriter()
                Dim hw As New System.Web.UI.HtmlTextWriter(tw)
                Dim frm As HtmlForm = New HtmlForm()
                Response.ContentType = "application/vnd.ms-excel"
                Response.AddHeader("content-disposition", "attachment;filename=" & "COP_Review_" & FormatDateTime(Now, DateFormat.ShortDate).Replace("/", "_") & ".xls")
                Response.Charset = ""
                EnableViewState = False
                Controls.Add(frm)
                frm.Controls.Add(GridView1)
                frm.RenderControl(hw)
                Response.Write(tw.ToString())
                Response.End()
                GridView1.AllowPaging = True
                GridView1.AllowSorting = True
                GridView1.DataBind()
            Else
                MsgBox("Too many rows - Export to Excel not possible")
            End If
        End Sub

    Comment

    Working...