Subject: BINDING DATA WITH SIMPLE CONTROLS
Posted By: saraswathyrajaram Post Date: 8/29/2006 11:36:13 AM
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
Reply By: dparsons Reply Date: 8/29/2006 12:15:35 PM
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."
Reply By: saraswathyrajaram Reply Date: 8/29/2006 12:46:18 PM
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>

Reply By: dparsons Reply Date: 8/29/2006 12:52:44 PM
Remove 'Price' from between your label tags and trying using Container.Dataitem("Price") instead.

"The one language all programmers understand is profanity."
Reply By: saraswathyrajaram Reply Date: 8/29/2006 12:59:40 PM
<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'"



Reply By: dparsons Reply Date: 8/29/2006 1:12:49 PM
I said, try using Container.Dataitem("Price"), remove the databinder.eval.

"The one language all programmers understand is profanity."
Reply By: saraswathyrajaram Reply Date: 8/29/2006 1:17:42 PM

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>

Reply By: dparsons Reply Date: 8/29/2006 1:30:11 PM
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."
Reply By: saraswathyrajaram Reply Date: 8/29/2006 2:05:43 PM
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

Reply By: dparsons Reply Date: 8/29/2006 2:08:08 PM
you wouldnt use the second for loop; and you cant use C# braces [ ] in VB.

"The one language all programmers understand is profanity."
Reply By: saraswathyrajaram Reply Date: 8/29/2006 2:28:29 PM
Dim dc As DataColumn
            Dim dr As DataRow
            For Each dr In Dstrail1.Tables(0).Rows

                lblPrice1.Text = dr(dc."Price".ToString() )

I AM SORY, STILL IT SAYS,, "IDENTIFIER REQIRED"



            Next


Reply By: dparsons Reply Date: 8/29/2006 2:38:42 PM
There are variances in C# and vb, and this case is no different.

In vb, you must qualify the column you are referencing with .item so:

dr.item("Price")

You do NOT call a data colum object inside of datarow object.



"The one language all programmers understand is profanity."
Reply By: saraswathyrajaram Reply Date: 8/29/2006 3:01:50 PM
thanks i got that error corrcted,
but i am struggling with some more code
shall i seek ur advice


Reply By: dparsons Reply Date: 8/29/2006 3:09:02 PM
post in the forums someone will answer it.

"The one language all programmers understand is profanity."

Go to topic 49021

Return to index page 190
Return to index page 189
Return to index page 188
Return to index page 187
Return to index page 186
Return to index page 185
Return to index page 184
Return to index page 183
Return to index page 182
Return to index page 181