Posts

Showing posts with the label Datagrid

Exporting datagrid to Excel using C#.net

Datagrid is one of the most coolest controls in the Asp.net. One thing that all developers need is to put the data grid data into excel sheet. In this article I will show you that how you can export your datagrid data to Excel file. Exporting datagrid to excel might sounds complex but its pretty simple. Let's see how this can be done. Here is the code: protected void img_Export_Click(object sender, EventArgs e) { // export to excel DataTable dt = new DataTable(); dt.Columns.Add("a"); dt.Columns.Add("b"); dt.Columns.Add("c"); dt.Rows.Add(); dt.Rows[0]["a"] = "aaaaaaaaaaaaaa"; dt.Rows[0]["b"] = "bbbbbbb"; dt.Rows[0]["c"] = "ccccccccccc"; dt.Rows.Add(); dt.Rows[1]["a"] = "11111111111111111"; dt.Rows[1]["b"] = "222222222222"; dt.Rows[1]["...