简体   繁体   中英

Bind label to DataSource.TotalRowCount

I have a custom DataSourceControl class that I'm using somewhat like a view model. 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. I can update the label from the code-behind, but that's not very 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.

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.
  2. You need to call Page.DataBind() in your code behind.

Hope that helps!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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