Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2006, 12:00 PM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Both DataSource and DataSourceID are defined

hi all

trying to assign a dataset to a DetailsView and i'm getting the error: Both DataSource and DataSourceID are defined on 'DataView'

assigning the dataset in the .vb as such:
DataView.DataSource = myDataSet
DataView.DataBind()

and assigning it to the DetailsView as such:
<asp:DetailsView id="DataView" runat="server" CssClass="Grid"
            AutoGenerateRows="true">

any suggestions on what i'm doing wrong here?

 
Old August 25th, 2006, 12:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

from microsoft:

"Note that you can't have both DataSource and DataSourceID set at the same time. When this happens, an invalid operation exception is thrown."

but better read all the article:
http://msdn.microsoft.com/library/de.../databound.asp

for what i see you are binding the dataview two times, but better read that...

HTH

Gonzalo
 
Old August 25th, 2006, 12:26 PM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks.

I read that, too.

Unfortunately, it didn't leave me with any solution. If, in my <asp:DetailsView... code, I set:

DataSourceID="DataView"

then I get "Name 'DataView' is not declared'

in the code behind at

DataView.DataSource = myDataSet

 
Old August 25th, 2006, 12:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mm... this has to be something really easy to find..

can you send out your page and the code behind (clear it to the important parts) to see if you are filling the dataview datasourceid property before you are calling to the databind..
what if you just take out the first code you show without doing anything else??
did it fill the grid?
if that the only place where you fill the grid??

HTH

Gonzalo
 
Old August 25th, 2006, 12:59 PM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i've got on the code behind


Dim wsVessel As New apm.new.service.Service()
Dim myDataSet As New Data.DataSet

If Request.QueryString("id") <> "" Then
            label1.Text = "<b>Container Number: " & Request.QueryString("id") & "</b>"
            myDataSet = wsVessel.GetContainerAvailabilty(Request.QueryStri ng("id"))

        End If

        Try
            DataView.DataSource = myDataSet
            DataView.DataBind()
        Catch ex As Exception
            label1.Text = "No Results Found"
        End Try

and on the .aspx file
<asp:DetailsView DataSourceID="DataView" runat="server" CssClass="Grid" AutoGenerateRows="true">



 
Old August 25th, 2006, 01:02 PM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...sorry, hit enter to quickly.

anyhow, that's my code as it is right now; and, i'm getting "Name 'DataView' is not declared" on DataView.DataSource = myDataSet


 
Old August 25th, 2006, 01:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

and it's ok.. datasourceID is the ID of the source of data, if you want to call your grid dataview you need something like ID="DataView", try to rename the grid, take uot the datasourceid and try again...



HTH

Gonzalo
 
Old August 25th, 2006, 01:49 PM
Registered User
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 <asp:DetailsView ID="myData" DataSourceID="DataView" runat="server" />

still not getting it. changed the "ID" of my DetailsView to "myData" and set the DataSourceID to "DataView" -- which is the databound dataset. Still getting "Name 'DataView' is not declared." How am i supposed to set the Databound dataset to the DetailsView grid?

 
Old August 25th, 2006, 02:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok.. let's start over.. take out the datasourceid.

instead of mydata put there dataview and try again.

when are you executing the bind?? on the load??
are you taking in mind postbacks???

HTH

Gonzalo
 
Old August 25th, 2006, 02:39 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You may be confused by what a DataSource is. In .NET 1,x many things could be a data source, like a DataSet, DataTable, arrays and so.

That still holds true in .NT 2. However, now there is also a DataSource *control* that you can drag from the Toolbox on your page. When you use a DataSource control you need to set the DataSourceId.

However, in your case, you're using old skool databinding. So, you don't need a DataSourceId and you don't need to name it. You may be confused and think that your data set is a named data source, which is not. The following is all you need:

<asp:GridView id="MyGridView" runat="Server" AutoGenerateRows="true" />

Code behind:

MyGridView.DataSource = myDataSet
MyGridView.DataBind()

Notice that MyGridView refers to the GridView in the markup of the page.

That's it.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB.Connection user-defined type not defined Wall st Guru Excel VBA 2 March 26th, 2014 03:44 PM
Object datasource VS DataSource SoftMind BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 July 27th, 2006 10:44 PM
Appl-defined or Object-defined error 1004 chp Excel VBA 3 April 4th, 2006 08:12 AM
User-defined type not defined (Icecream.mdb) dloren01 BOOK: Beginning Access VBA 0 June 22nd, 2005 10:36 PM
Application-defined or object-defined error James Excel VBA 1 August 12th, 2003 11:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.