在vb asp.net webform中,我在网格视图数据绑定过程中有一个select case语句,该语句基于存储在变量中的下拉列表中的值。
Protected Sub gvProgressGrid_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvProgressGrid.DataBound
Dim strYear As String = DdlYear.Text
Select Case strYear
Case 11
gvProgressGrid.Visible = True
Case 10
gvProgressGrid.Visible = True
Case 9
gvProgressGrid.Visible = True
Case 8
gvProgressGrid.Visible = False
Case 7
gvProgressGrid.Visible = False
End Select
End Sub默认情况下,网格视图显示,当我从下拉菜单中选择7或8时,网格视图消失。然而,一旦消失,如果我选择9-11,那么网格就不会重新出现。
发布于 2013-07-03 02:08:36
我不会为Gridview使用Databound事件,而是使用DropDownList的SelectedIndexChanged事件来容纳以下逻辑:
Protected Sub DdlYear_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DdlYear.SelectedIndexChanged
Dim strYear As String = DdlYear.Text
Select Case strYear
Case 11
gvProgressGrid.Visible = True
Case 10
gvProgressGrid.Visible = True
Case 9
gvProgressGrid.Visible = True
Case 8
gvProgressGrid.Visible = False
Case 7
gvProgressGrid.Visible = False
End Select
End Sub这在语义上更有意义,因为结果取决于dropdown (DdlYear.Text)的值。
它也可能运行得更正确,因为我认为这个问题与GridView的数据绑定方式有关(它可能只在第一个页面加载时进行数据绑定,而不是在回发时)。
https://stackoverflow.com/questions/17430114
复制相似问题