1

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.

NullEntity
  • 152
  • 11

2 Answers2

2

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!

Community
  • 1
  • 1
cthrall
  • 329
  • 1
  • 4
  • Thank you very much. Removing the Eval gave me syntax highlighting that showed me TotalRowCount isn't a property of the data source like I thought. It looks like it's a member of the selecting event and I'll have to update a property when that's called. – NullEntity Jan 05 '16 at 16:31
0

you must call Page.Databind() in Page_Load Method

Name
  • 69
  • 8