I Can't Show the Total Number of Users with Eval, Repeater, SqlDataSource and Count

44 Views Asked by At

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([userid]) FROM [user] WHERE ([isactive] = @isactive)">
    <SelectParameters>
        <asp:Parameter DefaultValue="True" Name="isactive" Type="Boolean" />
    </SelectParameters>
</asp:SqlDataSource>
1

There are 1 best solutions below

0
On

Your select command not including userid field. You can change your command as

SELECT COUNT([userid]) as userid FROM [user] WHERE ([isactive] = @isactive)

then Eval can find this column from your data source.