Feb 28, 2014
Export DataGridview To Excel
See the code
References:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.IO;
Code
for button for exporting to Excel
SaveFileDialog sfd = new
SaveFileDialog();
sfd.Filter = "Excel
Documents (*.xls)|*.xls";
sfd.FileName = "export.xls";
if (sfd.ShowDialog() == DialogResult.OK)
{
//ToCsV(dataGridView1, @"c:\export.xls");
ToCsV(dataGridView1, sfd.FileName); // Here
dataGridview1 is your grid view name
}
Function
for exporting to Excel:
private void
ToCsV(DataGridView dGV, string filename)
{
string stOutput = "";
// Export titles:
string sHeaders = "";
for (int j = 0; j
< dGV.Columns.Count; j++)
sHeaders =
sHeaders.ToString() + Convert.ToString(dGV.Columns[j].HeaderText)
+ "\t";
stOutput +=
sHeaders + "\r\n";
// Export data.
for (int i = 0; i
< dGV.RowCount - 1; i++)
{
string stLine = "";
for (int j = 0; j
< dGV.Rows[i].Cells.Count; j++)
stLine
= stLine.ToString() + Convert.ToString(dGV.Rows[i].Cells[j].Value)
+ "\t";
stOutput +=
stLine + "\r\n";
}
Encoding utf16 = Encoding.GetEncoding(1254);
byte[] output = utf16.GetBytes(stOutput);
FileStream fs = new
FileStream(filename, FileMode.Create);
BinaryWriter bw = new
BinaryWriter(fs);
bw.Write(output, 0, output.Length); //write
the encoded file
bw.Flush();
bw.Close();
fs.Close();
}
Feb 6, 2014
Sample Database Class
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
Nov 2, 2013
Avoid submit event Refresh in Asp.net
'Declare variables for use
Private
_refreshState As Boolean
Private _isRefresh As
Boolean
'Functions to Use
#Region " ISREFRESH
"
Protected Overrides Sub
LoadViewState(ByVal savedState As Object)
Dim
AllStates As Object()
= savedState
MyBase.LoadViewState(AllStates(0))
_refreshState = Boolean.Parse(AllStates(1))
_isRefresh = _refreshState = Session("__ISREFRESH")
End Sub
Protected Overrides Function
SaveViewState() As Object
Session("__ISREFRESH")
= _refreshState
Dim
AllStates() As Object
= New Object(2)
{}
AllStates(0) = MyBase.SaveViewState
AllStates(1) = Not
(_refreshState)
Return
AllStates
End Function
#End Region
'Call function in Button Click Event
Protected Sub
btnLogin_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles
btnLogin.Click
If
_isRefresh = True Then
Exit
Sub
End If
End Sub
Aug 19, 2013
How to Save and Retrieve File in SQL Server Table
1.) Design
2.) Table
| Save and Retrieve File in SQL Table : | ||
| Select File To Upload : | ||
| File ID to Download : | ||
2.) Table
|
Subscribe to:
Posts (Atom)
-
Bootstrap css front-end framework. jQuery fast, small, and feature-rich JavaScript library. DataTables advanced interaction contro...
-
<body> <form id="form1" runat="server"> <img class="RibbonL" src="Imag...
-
click on below link to send sms http://www.eggheadcafe.com/community/asp-net/17/10281633/code-to-send-sms-using-webservice-like-way2sms.as...
What is the use of n-tier architecture and 3-tier architecture?
how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it ...


