export data from datagrid to excel sheet
-
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
-
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
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::-
-
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::-
Thankyou zenithmaximus, iam getting at savedialoguebox(SD) iam using datagrid and also iam using paging for datagrid. srinivas
-
Thankyou zenithmaximus, iam getting at savedialoguebox(SD) iam using datagrid and also iam using paging for datagrid. srinivas
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::-
-
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::-
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