Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. export data from datagrid to excel sheet

export data from datagrid to excel sheet

Scheduled Pinned Locked Moved C#
sysadminhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    srinivassam
    wrote on last edited by
    #1

    hello , i want to export data from datagrid to excel sheet iam getting one error, error: Control 'DataGrid1__ctl3__ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server. iam getting error at this line DataGrid1.RenderControl(htmlWrite); please give me any advice srinivas

    Z 1 Reply Last reply
    0
    • S srinivassam

      hello , i want to export data from datagrid to excel sheet iam getting one error, error: Control 'DataGrid1__ctl3__ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server. iam getting error at this line DataGrid1.RenderControl(htmlWrite); please give me any advice srinivas

      Z Offline
      Z Offline
      zenithmaximus
      wrote on last edited by
      #2

      Hi, Hope this code help private void button1_Click(object sender, System.EventArgs e) { SaveFileDialog SD= new SaveFileDialog(); SD.Filter = "csv|*.csv|Comma Seperated Files|*.csv|All Files|*.*"; SD.InitialDirectory = @"C:\"; if (SD.ShowDialog() == DialogResult.OK) { using (System.IO.StreamWriter writer = new System.IO.StreamWriter(SD.FileName)) { int Colcnt = dsResults.Tables["tbl_Master_Pol_Lst"].Columns.Count; int Rowcnt = dsResults.Tables ["tbl_Master_Pol_Lst"].Rows.Count; for(int x=0;x<=(Colcnt-1);x++) { writer.Write(dsResults.Tables["tbl_Master_Pol_Lst"].Columns[x].ColumnName.Trim()+ ","); } writer.WriteLine(); for(int x=0;x<=(Rowcnt-1);x++) { for(int y=0;y<=(Colcnt-1);y++) { if (y == 2) { writer.Write("'" + dsResults.Tables["tbl_Master_Pol_Lst"].Rows[x].ItemArray.GetValue(y)+ ","); } else { String varData = Convert.ToString(dsResults.Tables["tbl_Master_Pol_Lst"].Rows[x].ItemArray.GetValue(y)); writer.Write(varData.Replace(","," ")+ ","); } } writer.WriteLine(); } writer.Flush(); MessageBox.Show(SD.FileName + " successfully created"); } }

      -::maximus::-

      S 1 Reply Last reply
      0
      • Z zenithmaximus

        Hi, Hope this code help private void button1_Click(object sender, System.EventArgs e) { SaveFileDialog SD= new SaveFileDialog(); SD.Filter = "csv|*.csv|Comma Seperated Files|*.csv|All Files|*.*"; SD.InitialDirectory = @"C:\"; if (SD.ShowDialog() == DialogResult.OK) { using (System.IO.StreamWriter writer = new System.IO.StreamWriter(SD.FileName)) { int Colcnt = dsResults.Tables["tbl_Master_Pol_Lst"].Columns.Count; int Rowcnt = dsResults.Tables ["tbl_Master_Pol_Lst"].Rows.Count; for(int x=0;x<=(Colcnt-1);x++) { writer.Write(dsResults.Tables["tbl_Master_Pol_Lst"].Columns[x].ColumnName.Trim()+ ","); } writer.WriteLine(); for(int x=0;x<=(Rowcnt-1);x++) { for(int y=0;y<=(Colcnt-1);y++) { if (y == 2) { writer.Write("'" + dsResults.Tables["tbl_Master_Pol_Lst"].Rows[x].ItemArray.GetValue(y)+ ","); } else { String varData = Convert.ToString(dsResults.Tables["tbl_Master_Pol_Lst"].Rows[x].ItemArray.GetValue(y)); writer.Write(varData.Replace(","," ")+ ","); } } writer.WriteLine(); } writer.Flush(); MessageBox.Show(SD.FileName + " successfully created"); } }

        -::maximus::-

        S Offline
        S Offline
        srinivassam
        wrote on last edited by
        #3

        Thankyou zenithmaximus, iam getting at savedialoguebox(SD) iam using datagrid and also iam using paging for datagrid. srinivas

        Z 1 Reply Last reply
        0
        • S srinivassam

          Thankyou zenithmaximus, iam getting at savedialoguebox(SD) iam using datagrid and also iam using paging for datagrid. srinivas

          Z Offline
          Z Offline
          zenithmaximus
          wrote on last edited by
          #4

          Thankyou zenithmaximus, iam getting at savedialoguebox(SD) <- you mean getting confused? iam using datagrid and also iam using paging for datagrid. the save dialogue statements is where you specify the path of where you're saving the data from your datagrid to a CSV file. The code applies to a scenario where you're saving your exported data from datagrid to a CSV(excel like) file, from clicking a botton. :-D

          -::maximus::-

          S 1 Reply Last reply
          0
          • Z zenithmaximus

            Thankyou zenithmaximus, iam getting at savedialoguebox(SD) <- you mean getting confused? iam using datagrid and also iam using paging for datagrid. the save dialogue statements is where you specify the path of where you're saving the data from your datagrid to a CSV file. The code applies to a scenario where you're saving your exported data from datagrid to a CSV(excel like) file, from clicking a botton. :-D

            -::maximus::-

            S Offline
            S Offline
            srinivassam
            wrote on last edited by
            #5

            iam getting error near save dialogue box C:\Inetpub\wwwroot\UserManagement\userdetails1.aspx.cs(170): The type or namespace name 'SaveFileDialog' could not be found (are you missing a using directive or an assembly reference?) srinivas

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups