[英]asp.net Row Count VB.NET
因此,我想計算使用下拉列表過濾后當前在gridview中可以看到的項目的行數。
如果我選擇一個新項目,它將顯示我先前選擇的值的計數
例如,我在DDL中選擇Beamer,其中有4個項目,但是在此之前,我選擇了Copier,並且其中有8個項目,選擇Beamer之后,我的標簽將在復印機中顯示8個項目,依此類推。
我的代碼:
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
<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>
我相信問題在於ddlType_SelectedIndexChanged
事件上的代碼在您的數據過濾器之前執行,因此您更改了ddl上的值,它計算了gridview上的當前行,然后更新了gridview。 您需要在Gridview DataBind()
之后移動代碼
在這里查看所有網格視圖事件
我看到您使用了selectedindexchanged
事件。 加載網格后發生此事件。 您應該改用selectedindexchanging
事件,該事件在加載網格之前觸發。
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.