0

所以我试图使用标签来显示我存储在数据库表中的记录。此表中只有一条记录。

//在页面顶部声明类

 protected Invoice invoice_Info;

   myDataBase db = new myDataBase();

   invoice_Info =
            (from invoiceInfo in db.Invoice_Infos
             select invoiceInfo).FirstOrDefault();

                labelBindforInvoiceDetails.DataBind();

然后在我的 aspx 页面中,我正在使用:

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

但是代码给我一个“绑定”错误数据绑定方法,例如 Eval()、XPath() 和 Bind(),只能在数据绑定控件的上下文中使用。

4

2 回答 2

1

那是对的。标签不是数据绑定控件。将标签放在Repeater(这是一个数据绑定控件)中。然后可以绑定里面的控件(即你的标签)。

或者

取出绑定并在后面的代码中执行此操作

            labelBindforInvoiceDetails.Text = invoice_Info.ToString()
于 2013-01-28T17:16:24.343 回答
1

您需要对 Header 进行数据绑定,然后查看它是否有效。

Page.DataBind()

检查此以获取另一个解决方案http://www.mikesdotnetting.com/Article/64/Bind-Data-From-a-SqlDataSource-to-a-Label

于 2013-01-28T17:10:20.670 回答