.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Binding Grid to Excel Doc

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :WPF
I used the below code, and all i get is empty rows of data for each of the represented rows in my Excel doc. Am I doing something wrong?: private void btnUploadExcelToGrid_Click(object sender, RoutedEventArgs e) { string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileSouce + ";Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn); OleDbDataAdapter da = new OleDbDataAdapter(); da.SelectCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", conn); DataTable dt = new DataTable(); da.Fill(dt); dgExcel.DataContext = dt; } I do not have ACE installed on my dev box, and I am only using office 2k3, so Excel 8.0 made sense to me.  Here is a pic of what I get back: http://www.facebook.com/photo.php?pid=547091&l=32e9fb3745&id=1811331443  Charles Charles

View Complete Post

More Related Resource Links

Binding WPF grid to ViewModel : Suggest the design

I have structure like this I have following structure BaseViewModel ViewModel1: BaseviewModel ViewModel2: BaseViewModel In grid i will be showing the data from both the ViewModel1 and ViewModel2 (some common data is there ) How should i go about this Expected functionality : IF i select any row in the grid i should get respective ViewModel    

Unable to export data to an excel file in grid format!!!

I'm exporting data to an excel sheet from the ojects list. The data is exporting to excel sheet well, but I'm unable to see the grid format for the data. The data is looking with out the rows and columns lines. I think I'm missing to set some property or somethnig ehwn exporting.   Any help would be really appriciated.

Output data grid as excel

Hi,I'm trying to output a data grid as excel when someone clicks a button on a web page.I have the data grid working and have found some code to do the excel output, but can't quite get it working.  The code is like this:using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections.Generic; using System.Linq; using System.IO; using System.Web; using System.Web.UI; using umbraco; namespace MyDataExport { public partial class ExportData : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); } } private void BindGrid() { SqlDataReader reader; SqlConnection conn = new SqlConnection(GlobalSettings.DbDSN); SqlCommand comm = new SqlCommand("SELECT * FROM budgetData;", conn); try { conn.Open(); reader = comm.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind(); reader.Close(); } finally { conn.Close(); } } private void btnExportToExcel_Click(object sender,System.EventArgs e) { ExportToExcel("Report.xls", DataGrid1); //This line is erroring, saying 'DataGrid1 does not exist in the current context' } private void ExportToExcel(string strFileName, DataGrid dg) //This line errors, saying 'The type or namespace name DataGrid c

Grid view: menu item of hyperlink to view attachment excel and pdf

Good day,

i am facing a problem to create a hyperlink to view the attachment pdf and excel in table from a menu item i created.

below is my coding, themnuItem.NavigateUrl is wrong, i hope anyone can help me. i attach the printscreen of my table and the menu item, however i fail to make the hyperlink from the view image to my attachment.

i had a css file to create the menu item



            Dim models_select As String = Cmn.ReplaceDBNull(Me.gridView1.DataKeys(e.Row.RowIndex).Values("MODEL_SELECT"), "")
            Dim mnuAction As Menu = CType(e.Row.FindControl("mnuAction"), Menu)
            Dim mnuRoot As MenuItem
            Dim mnuItem As MenuItem
            'Dim CCLID As String = Cmn.ReplaceDBNull(Me.gridView1.DataKeys(e.Row.RowIndex).Values("CCLID"), "")

            ' Insert root item
            mnuRoot = New MenuItem()
            mnuRoot.Text = models_select & " "
            mnuRoot.NavigateUrl = ""
            mnuRoot.Selectable = False

Exporting Data From Data Grid to Excel Or World



i am facing the problem in the exporting the data from the datagrid to excel, I have master page concept in the project where as i am trying to create the export function in the child contrl.

on the button click i wrote the below code

            Response.AddHeader("Content-Disposition", "Attachment; FileName = FileName.xls");
            Response.Charset = "";
            Response.ContentType = "Application/vnd.xls";

Binding to a grid row height, with splitter works until splitter is used.


I hava a grid with two rows and a splitter, and it works fine.

I want the ability to show only one row(make the other one collapse), so I created binding between the second row height to a member in my view model.

When something happen(button click) I change the member value in my view model and the row disappear. on next click the row comes back and everything works fine.

The problem is that if I press button and use splitter, the binding stops working and on next clicks nothing happens.


I know I can write a specific ui side code that work without the binding, I prefer not to.

Help please.

Binding a Grid via WCF Data Services


Hello everybody,

i am trying to bind a grid to a database via the internet. I did this for years and every time i do it, i am looking for new ways to do it. So this time i will give WCF Data Services a chance. But wait... after the first "solutions" i tried i figured out that nothing changed the years. I seems to be not easy at all....

The Idea of binding a grid to a database is, that the user see's data, can filter, search and sort on each column. And because we don't know the amount of rows we need a way to only load "some" of the rows and refetch at a time. This is a minimum requirement for each grid. So this is the goal. This means in case of the internet, that the query must be transferred to the server and the server should only return the data that was requested. It also means, that the grid must fetch only "some" rows and refetch the rest of the rows when the user is scrolling down.

Can WCF Data Services do that? Can the grid of .NET do that? Can the Telerik Grid do that or any other grid? 

I tried some of the examples called "binding grid to wcf data services", but none of them could do it. Maybe someone has a simple solution for it? Or do i have to write that my own?

Thanks for your help ... regards




Copy phone numbers from results grid to excel, numbers have leading 0


Hi I need to copy a column of phone numbers into excel they should be treated as text however excel wants to treat it as a number.

Is there anything I can do to force excel to treat the copy and paste from management studio as text and retain the leading 0?

Getting multiple rows from oracle stored procedure and binding it to grid view



To  get this stuff you need to create a Ref Cursor to return recordset.

             create or replace PACKAGE Types AS

            TYPE cursor_type IS REF CURSOR;

            END Types;

Now create a stored procedure to return multiple rows .

           create or replace

           PROCEDURE getAllCity(p_recordset OUT types.cursor_type) AS


           OPEN p_recordset FOR


Problem with resizing images and padding them to squared images before binding them to grid



I am developing a web application in ASP.NET and C# using Visual Studio 2008. The application will among other thing store images into a database in the original format and in some resized formats. I have this method that takes an image as argument and returns an image with the specified size:

thumbnailmage = ResizeImage(originalImage, new Size(50,50));

The image returned is proportional to the original image with no side bigger than 50 pixels. E.g. if the originalImage has width 100 and height 200 the resized image has width 25 and height 50. This result is expected and wanted.

Now, to what I really want. I want to modify the ResizeImage method to return a squared thumbnail. I.e. in the originalImage example sizes above, the returned image should have width width and heigth both 50. Also, the image should not be stretched but padded with 12.5 pixels on the left and right side making the width 50. The image format I currently work with is gif with transparent background so the padded image parts should also be tansparent. Here is the code for ResizeImage, does anyone know how it could be modified?

  private static Image ResizeImage(Image imageToResize, Size size)
      int sourceWidth = imageToResize.Width;
      int sourceHeight = imageToResize.Height;


Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Export Visio Database Table Names to Excel

If you use the Enterprise Architect edition of Microsoft Visio for data modeling regularly, then there is a good chance that at some point you've wanted to export just the table names into Excel. You might want to do this to map logical ERD entities to physical data model tables, track project status by entity, or track overlap between database versions.

Excel Automation in .Net

Excel Automation is a buzz word in both webapps and winapps. In the programming life (like Mr.Anderson neo) I guess almost every one could have come across this word. For others let me go further in detail. Excel Automation is automating some or all of the process involved in creating or updating excel worsheets.

Binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Here is the code for binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Building a grouping Grid with GridView and ASP.NET AJAX toolkit CollapsiblePanel

I've posted an update to this post to apply on demand loading of Details data using ASP.NET AJAX PageMethods. I'm demonstrating the usage if CollapsiblePanelExtender client events on the new post. Check it out.

I admit, Matt Berseth is really inspiring me! Few days ago I pass through 2 of his great posts:

.Surrounding your Data Table and Dialog Controls with ComponentArt Styled Panels
.Building a Grouping Grid with the ASP.NET 3.5 LinqDataSource and ListView Controls
The first one is pure design tips one which I used for making good presentation of my demo here. The 2nd post is actually the idea.

display data into GridView from excel sheet

I have to display data from excel sheet into my gridview and also I need to figure out a way to store data into excel files from my web page. I am using C# 3.5, VS 2008.

Export SharePoint List to Excel Spreadsheet Programmatically using C#

In SharePoint applications, Custom Lists are used to store business data and Document Libraries to store the documents. But for data manupulation and analysis, Microsoft Excel provides very rich features as compared to SharePoint Lists. That's why people still loves to work on Microsoft Excel Sheets.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend