2 Replies - 738 Views - Last Post: 29 January 2013 - 03:42 AM Rate Topic: -----

#1 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

label binding trouble

Posted 28 January 2013 - 10:08 AM

Hey Guys...So i'm attempting to use a label to display a record I have stored in a table in the DB. There is only one record in this table.

//declare class at top of page


     protected Invoice invoice_Info;
    
       myDataBase db = new myDataBase();
            
       invoice_Info =
                (from invoiceInfo in db.Invoice_Infos
                 select invoiceInfo).FirstOrDefault();
            
                    labelBindforInvoiceDetails.DataBind();


Then in my aspx page I am using:

    <span>                             
     <asp:Label id="labelBindforInvoiceDetails" runat="server" Text="<%# Bind('invoice_Info') %>"/>                                  
     </span>



But the code is throwin me an error with 'bind' Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Is This A Good Question/Topic? 0
  • +

Replies To: label binding trouble

#2 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 262
  • View blog
  • Posts: 1,460
  • Joined: 07-April 08

Re: label binding trouble

Posted 28 January 2013 - 10:40 AM

Labels are not databound by default. If you had it in a control such as a grid or repeater then it would be able to use EVAL or BIND.

Instead of calling DataBind() on the label why not just set the text itself to something within invoice_Info.
Was This Post Helpful? 0
  • +
  • -

#3 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

Re: label binding trouble

Posted 29 January 2013 - 03:42 AM

thats great thank ye
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1