简体   繁体   English

asp.net行数VB.NET

[英]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. 因此,我想计算使用下拉列表过滤后当前在gridview中可以看到的项目的行数。

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. 例如,我在DDL中选择Beamer,其中有4个项目,但是在此之前,我选择了Copier,并且其中有8个项目,选择Beamer之后,我的标签将在复印机中显示8个项目,依此类推。

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. 我相信问题在于ddlType_SelectedIndexChanged事件上的代码在您的数据过滤器之前执行,因此您更改了ddl上的值,它计算了gridview上的当前行,然后更新了gridview。 You need to move your code after your Gridview DataBind() 您需要在Gridview DataBind()之后移动代码

See here all the events of grid view 在这里查看所有网格视图事件

I see you have used selectedindexchanged event. 我看到您使用了selectedindexchanged事件。 This event occurs AFTER the grid is loaded. 加载网格后发生此事件。 You should use selectedindexchanging event instead which is fired BEFORE the grid is loaded. 您应该改用selectedindexchanging事件,该事件在加载网格之前触发。

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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