简体   繁体   English

将标签绑定到DataSource.TotalRowCount

[英]Bind label to DataSource.TotalRowCount

I have a custom DataSourceControl class that I'm using somewhat like a view model. 我有一个自定义的DataSourceControl类,在使用时有点像视图模型。 I'm coming from WPF databinding land and I would like to be able to bind the text of a label to the TotalRowCount using a databinding expression. 我来自WPF数据绑定领域,我希望能够使用数据绑定表达式将标签文本绑定到TotalRowCount。 I can update the label from the code-behind, but that's not very MVVM. 我可以从后面的代码中更新标签,但这不是MVVM。 This sample generates a label with blank text: 此示例生成带有空白文本的标签:

<cc:EquipmentDataSource ID="edsEquipment" runat="server"></cc:EquipmentDataSource>
<asp:Label ID="Label1" runat="server" text='<%# Eval("edsEquipment.TotalRowCount") %>'></asp:Label>

Am I misunderstanding something about how the databinding works? 我是否对数据绑定的工作方式有误解? I was getting the same empty string when I used an ObjectDataSource as well. 当我也使用ObjectDataSource时,我得到的是相同的空字符串。

Based on this answer , it would appear two things need to change: 根据此答案 ,似乎需要更改两件事:

  1. You don't need the Eval, the value of the Text attribute can be the property name on your data object. 您不需要Eval,Text属性的值可以是数据对象上的属性名称。
  2. You need to call Page.DataBind() in your code behind. 您需要在后面的代码中调用Page.DataBind()

Hope that helps! 希望有帮助!

您必须在Page_Load方法中调用Page.Databind()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM