Wrox Programmer Forums
|
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 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 29th, 2006, 11:36 AM
Registered User
 
Join Date: Aug 2006
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
 
Old August 29th, 2006, 12:15 PM
Wrox Author
 
Join Date: Oct 2005
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."
 
Old August 29th, 2006, 12:46 PM
Registered User
 
Join Date: Aug 2006
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>

 
Old August 29th, 2006, 12:52 PM
Wrox Author
 
Join Date: Oct 2005
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."
 
Old August 29th, 2006, 12:59 PM
Registered User
 
Join Date: Aug 2006
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'"



 
Old August 29th, 2006, 01:12 PM
Wrox Author
 
Join Date: Oct 2005
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."
 
Old August 29th, 2006, 01:17 PM
Registered User
 
Join Date: Aug 2006
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>

 
Old August 29th, 2006, 01:30 PM
Wrox Author
 
Join Date: Oct 2005
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."
 
Old August 29th, 2006, 02:05 PM
Registered User
 
Join Date: Aug 2006
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

 
Old August 29th, 2006, 02:08 PM
Wrox Author
 
Join Date: Oct 2005
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."





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





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