简体   繁体   中英

asp.net Row Count VB.NET

So I want to count the rows of the items that I can currently see in the gridview after filtering with a Drop Down List.

If I select a new item it displays the count of the previous value I selected

Example, I select Beamer in the DDL and it has 4 items in it but before that I selected Copier and that one had 8 items in it, after selecting Beamer my label will show the 8 from the copier and so on.

My Code:

Protected Sub ddlType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlType.TextChanged

    Dim intAantal As Integer = gvRapportObjecten.Rows.Count
    lblAantal.Text = "Het aantal items is: " & intAantal.ToString

Picture

<asp:SqlDataSource ID="GridDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:LPIProjectConnection %>"
SelectCommand="SELECT object.id, object.label, object.object_type, object_type.name FROM object_type LEFT JOIN [object] ON object_type.id = object.object_type" FilterExpression="name  = '{0}'">
<FilterParameters>
    <asp:ControlParameter Name="name" ControlID="ddlType" PropertyName="SelectedValue" />
</FilterParameters>

I believe the problem is that the code on the ddlType_SelectedIndexChanged event its executed before your datafilter, so you change the value on the ddl, it counts the current rows on your gridview and then updates the gridview. You need to move your code after your Gridview DataBind()

See here all the events of grid view

I see you have used selectedindexchanged event. This event occurs AFTER the grid is loaded. You should use selectedindexchanging event instead which is fired BEFORE the grid is loaded.

I hope this helps.

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