Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 29th, 2006, 11:36 AM
Registered User
 
Join Date: Aug 2006
Location: norcross, georgia, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default BINDING DATA WITH SIMPLE CONTROLS

hi all

how can i bind data in a table with label control?
can i use like this

<asp:label id="lblPrice1" text= '<%# DataBinder.Eval("Price") %>' runat="server"/>

IT SAYS
"Overload resolution failed because no accessible 'Eval' accepts this number of arguments."

CAN ANYONE HELP ME IN THIS CONTEXT

THANKS
  #2 (permalink)  
Old August 29th, 2006, 12:15 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The reason you are getting the error is because the Databinder doesnt work like that you have to do:

DataBinder.Eval(Container.DataItem,"Price")
or
Container.DataItem("Price")

hth

"The one language all programmers understand is profanity."
  #3 (permalink)  
Old August 29th, 2006, 12:46 PM
Registered User
 
Join Date: Aug 2006
Location: norcross, georgia, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I WROTE THE WAY U SAID, BUT IT GIVES

"'DataItem' is not a member of 'System.Web.UI.Control'"

<asp:label id="lblPrice1" text= '<%# DataBinder.Eval(Container.DataItem,"Price") %>' style="Z-INDEX: 102; LEFT: 360px; POSITION: absolute; TOP: 208px"
                runat="server"/>PRICE</asp:label>

  #4 (permalink)  
Old August 29th, 2006, 12:52 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Remove 'Price' from between your label tags and trying using Container.Dataitem("Price") instead.

"The one language all programmers understand is profanity."
  #5 (permalink)  
Old August 29th, 2006, 12:59 PM
Registered User
 
Join Date: Aug 2006
Location: norcross, georgia, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<asp:label id=lblPrice1 style="Z-INDEX: 102; LEFT: 360px; POSITION: absolute; TOP: 208px" runat="server" text='<%# DataBinder.Eval(Container.DataItem,"Price") %>'/></asp:label>

BUT THE SAME ERRR
'DataItem' is not a member of 'System.Web.UI.Control'"



  #6 (permalink)  
Old August 29th, 2006, 01:12 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I said, try using Container.Dataitem("Price"), remove the databinder.eval.

"The one language all programmers understand is profanity."
  #7 (permalink)  
Old August 29th, 2006, 01:17 PM
Registered User
 
Join Date: Aug 2006
Location: norcross, georgia, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default


i am sorry, but its the same result getting
'DataItem' is not a member of 'System.Web.UI.Control'"

<asp:label id=lblPrice1 style="Z-INDEX: 102; LEFT: 360px; POSITION: absolute; TOP: 208px" runat="server" text='<%# Container.DataItem("Price") %>'/></asp:label>

  #8 (permalink)  
Old August 29th, 2006, 01:30 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The Databinder.Eval and Container.DataItem are designed to work inside of controls you have called Databind() on;

For example:

DataGrid.DataSource = DataTable;
DataGrid.DataBind();

If your label control is not inside a parent control that you are calling DataBind on, then you have to pragmatically set the text property:

foreach(DataRow dr in datatable){
  lblPrice1.text = dr["price"];
}

of course, if you are just returning just one row you dont need the for each loop, you can simply reference the column in the row that holds the data you want displayed in the label.




"The one language all programmers understand is profanity."
  #9 (permalink)  
Old August 29th, 2006, 02:05 PM
Registered User
 
Join Date: Aug 2006
Location: norcross, georgia, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dim dc As DataColumn
            Dim dr As DataRow
            For Each dr In Ds.Tables(0).Rows
                For Each dc In Ds.Tables(0).Columns
                    lblPrice1.text= dr(dc.["Price"].ToString())
                Next

            Next


IT SAYS "IDENTIFIER EXPECTED" NEAR ["Price"].ToString())

IS THIS THE CORRECT FORMAT OF "FOR LOOP" IN VB.NET?

THANKS

  #10 (permalink)  
Old August 29th, 2006, 02:08 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

you wouldnt use the second for loop; and you cant use C# braces [ ] in VB.

"The one language all programmers understand is profanity."
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding Controls zulf Infopath 0 October 8th, 2007 11:22 PM
ch02 - Binding to a Simple XML Document Tophat BOOK: Beginning ASP.NET 1.0 7 August 17th, 2007 05:09 AM
Binding controls Boris Kofman VB Databases Basics 1 January 20th, 2007 01:16 PM
Data Binding to List Controls dejawoo ASP.NET 1.0 and 1.1 Professional 2 July 3rd, 2004 10:54 PM



All times are GMT -4. The time now is 09:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.