 |
| 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
|
|
|
|

August 29th, 2006, 11:36 AM
|
|
Registered User
|
|
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 29th, 2006, 12:15 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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."
|
|

August 29th, 2006, 12:46 PM
|
|
Registered User
|
|
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

August 29th, 2006, 12:52 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Remove 'Price' from between your label tags and trying using Container.Dataitem("Price") instead.
"The one language all programmers understand is profanity."
|
|

August 29th, 2006, 12:59 PM
|
|
Registered User
|
|
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<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'"
|
|

August 29th, 2006, 01:12 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
I said, try using Container.Dataitem("Price"), remove the databinder.eval.
"The one language all programmers understand is profanity."
|
|

August 29th, 2006, 01:17 PM
|
|
Registered User
|
|
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

August 29th, 2006, 01:30 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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."
|
|

August 29th, 2006, 02:05 PM
|
|
Registered User
|
|
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 29th, 2006, 02:08 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
you wouldnt use the second for loop; and you cant use C# braces [ ] in VB.
"The one language all programmers understand is profanity."
|
|
 |