473,722 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problems importing excel workbook and displaying in dynamic datagrid

What I am attempting to do is import an Excel Workbook and display the
worksheets in a datagrid dynamically.

I am very close to getting this to work. I have to this point
successfully imported a single worksheet into a dataset. I successfully
built a dynamic datagrid. And I did successfully bind it to the
dataset. Then I added the datagrid control to a PlaceHolder. The first
worksheet displays beautifully.

The next step is to allow the user to move from one worksheet to the
next. I list the worksheets in a drop down list box. The user chooses
the second worksheet from the list.

I go through all of the same gyrations again. I load the worksheet into
the dataset, build the datagrid dynamically based upon the structure of
the second worksheet, and add the datagrid control to my PlaceHolder.

This is where the problem seems to arise.

It appears within QuickWatch that when I add the datagrid control to
the PlaceHolder the second time, although the underlying datasource
column info looks good, the datagrid column properties appear as they
were with the first worksheet.

This culminates in the following error message when I attempt to
DataBind() my datagrid:

"A field or property with the name <datagrid column name goes here> was
not found on the selected datasource."

I don't understand why it is doing this, since I am creating the
datagrid dynamically from scratch, DataGrid myDataGrid = new
DataGrid(), each time the aspx page is loaded.

I did theorize that the persistent nature of the datagrid properties
may have been caused by an enabled "View State". So I ensured that the
"View State" property of my PlaceHolder was set to false. However, this
did not correct the problem.

I also thought that I may need to explicitly remove the datagrid
control from PlaceHolder before adding it the second time. But it
appears in QuickWatch (as I would expect) that the PlaceHolder does not
have any controls attached to it until I invoke
PlaceHolder.Con trols.Add(dgWor ksheet).

Can anyone please help me? This is very puzzling and has moved beyond
tedious to possible showstopper. Thanks for your prompt reply(s).

My code is below.


Sincerely, -Van

_______________ __

dgWorksheet.Wid th=100;
dgWorksheet.Use InternalCSS=fal se;
dgWorksheet.Dat aSource=this.dv Worksheet;
dgWorksheet.All owSorting=true;
dgWorksheet.All owPaging=true;
dgWorksheet.Bor derColor=Color. White;
dgWorksheet.Bor derWidth=1;
dgWorksheet.Bac kColor=Color.Wh ite;
dgWorksheet.Ite mStyle.CssClass ="dgRowDark" ;
dgWorksheet.Cel lPadding=3;
dgWorksheet.Cel lSpacing=0;
dgWorksheet.Bor derStyle=Border Style.Outset;
dgWorksheet.Pag eSize=13;
dgWorksheet.Css Class="dgTable" ;
dgWorksheet.Ena bleViewState=fa lse;
dgWorksheet.Dat aKeyField=this. dsWorksheet.Tab les[0].Columns[0].ColumnName;

dgWorksheet.Pag erStyle.Horizon talAlign=Horizo ntalAlign.Right ;
dgWorksheet.Pag erStyle.CssClas s="dgFooter";
dgWorksheet.Pag erStyle.Mode=Pa gerMode.Numeric Pages;
dgWorksheet.Alt ernatingItemSty le.CssClass="dg RowLight";
dgWorksheet.Foo terStyle.CssCla ss="dgFooter";
dgWorksheet.Aut oGenerateColumn s = false;

BoundColumn[] bca=new BoundColumn[100];

// Add New Columns to DataGrid
for(int j=0; j < this.dsWorkshee t.Tables[0].Columns.Count; j++)
{
bca[j]=new BoundColumn();
bca[j].DataField=this .dsWorksheet.Ta bles[0].Columns[j].ColumnName;
bca[j].HeaderText=bca[j].DataField.Repl ace("_"," ");
bca[j].SortExpression =bca[j].DataField;
dgWorksheet.Col umns.Add(bca[j]);
}
dgWorksheet.Vis ible=true;
lblRowCount.Fon t.Size=5;
lblRowCount.Fon t.Name="Verdana ";
lblRowCount.Vis ible=true;

//Here is where the problem seems to arise.
//When I do a QuickWatch on dgWorksheet here, it appears with only
//datasource column info. All datagrid column info is not yet set.
//Those properties appear to be getting set upon databind the first
//time around, and everything is smooth.
//But when I go to the second worksheet, then the problem seems to
//Occur in this next statement.

// Add New Controls to WorksheetDataGr id

this.WorksheetD ataGrid.Control s.Add(dgWorkshe et);

//After executing the above statement the second time around,
//then the prior datagrid column properties seem to reappear,
//and I can't figure out why.
//Any help would be greatly appreciated.

this.WorksheetD ataGrid.Control s.Add(lblRowCou nt);
this.WorksheetD ataGrid.Visible =true;

this.DataBind() ;

Nov 19 '05 #1
0 1697

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3063
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the correct cells within that worksheet. The Excel Book is made up of 12 worksheets named Jan-Dec. Each worksheet has columns labeled as each day of that month. Column 'A' is reserved for 19 rows named "room1 - room19". The data I am importing from the...
2
2642
by: Bill Agee | last post by:
I am having difficulting importing an Excel spreadsheet into my Access program using VBA I want to use the last argument to specify the worksheet name which is RTA. I get an error which says that the name worksheet or path is incorrect. However, if I "rem" out the last parameter and make RTA the 1st sheet in the Excel workbook, everything is imported correctly. Unfortunately, I have several worksheets in the workbook which need to be...
9
3916
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. There is no further explanation. What are the kinds of things that make this happen? Thanks from an obvious rookie. Gordon
1
3821
by: Jerry J | last post by:
I am sending Excel reports to web clients. Excel opens in internet explorer displaying multiple sheets. It is pretty simple to do and works well. To do it, a client clicks a link to an ASPX page that first generates Excel.htm files (query string contains parameters for the specific reports) then uses Response.Write() to stream and Excel workbook file back to the client. The Workbook file, internally contains links to the Excel.htm files...
5
1832
by: Dave | last post by:
In a VB.NET application, I have a datagrid that I export to an Excel spreadsheet like this: ' Set the content type to Excel Response.ContentType = "application/vnd.ms-excel" Dim tw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' Get the HTML for the control.
1
2805
by: madeleine.macphail | last post by:
All I'm currently attempting to move us from a spreadsheet based system to a database system. The first phase is to import the data on a regular basis from the spreadsheets to get the database working the way we need it to prior to switching users over to it. Each team has a workbook, each workbook contains multiple worksheets, only some of the sheets contain the ranges that I want to import.
2
3500
by: madeleine | last post by:
I'm hoping the answer to this is that I'm just doing something silly, but I'm really scratching my head over this one. I'm importing data from multiple workbooks, each workbook has a sheet called SubSAT and I need to get specific data from that into the database. I'm finding that if I have the workbook open on my desktop then the SubSAT % complete and the High level plan % come in fine, but as soon as the workbook is closed they come...
5
2286
by: =?Utf-8?B?U3R1YXJ0?= | last post by:
Hi There I have been having a play around with the following code to display a datagrid in Excel (all from Steve Orr's site): Private Sub btnTechServAccred_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTechServAccred.Click Dim AcredDT As DataTable = UserSession.Current.AcredTable Dim aExcel As New Microsoft.Office.Interop.Excel.Application
0
3005
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from HRESULT: 0x800A03EC Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details:...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.