问题
I want to find the total number of active users who are members of the user
table in my database. But I get an error like this:
DataBinding: 'System.Data.DataRowView' does not contain a property with name 'userid'
My code is as follows:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<h3><%#Eval("userid") %></h3>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aytasarimConnectionString %>" SelectCommand="SELECT COUNT(*) FROM [user]"></asp:SqlDataSource>
回答1:
The error means that there is no column named userid
in the result from your query. And that makes sense since you are returning only one column. And you are not even naming that column with AS
, so SQL makes it Expr1
as column name.
your query should be
SELECT COUNT(*) AS total_users FROM [user]
Now you can use the column name total_users
in the Repeater
<h3><%#Eval("total_users") %></h3>
来源:https://stackoverflow.com/questions/46024579/databinding-system-data-datarowview-does-not-contain-a-property-with-the-name