2016-07-15 109 views
0

我目前正在從事一個項目。我突然偶然發現了一個真正讓我的大腦癱瘓的問題。我有一個函數將數據庫中的表格內容顯示給我命名爲bindGrid的gridview。當我查詢50到90條記錄時,它工作得很好。但是,當我查詢100條或更多記錄時,gridview不顯示記錄,直到我更改設置爲autopostback的下拉框的值。Gridview不刷新顯示更新記錄

這裏是代碼的樣本:

Protected Sub btnFilter_Click(sender As Object, e As EventArgs) Handles btnFilter.Click 
     If cboFilter.Text = "DMZ" Then 
      lblErrFilter.Visible = False 
      lblError.Visible = False 
      If drpYear.Text = "--Select--" Or drpMonth.Text = "--Select--" Or txtDMZ.Text = "--Select--" Or txtTop.Text = "" Then 
       If drpYear.Text = "--Select--" Then 
        lblErrYear.Visible = True 
       Else 
        lblErrYear.Visible = False 
       End If 
       If drpMonth.Text = "--Select--" Then 
        lblErrMonth.Visible = True 
       Else 
        lblErrMonth.Visible = False 
       End If 
       If txtDMZ.Text = "--Select--" Then 
        lblErrDMZ.Visible = True 
       Else 
        lblErrDMZ.Visible = False 
       End If 
       lblError.Visible = True 
       lblError.Text = "No value specified for the following parameter(s) *." 
      Else 
       lblErrYear.Visible = False 
       lblErrMonth.Visible = False 
       lblErrDMZ.Visible = False 
       Call bindData() 
       'If Me.IsPostBack = True Then 
       Call bindGrid() 
       'End If 
       ' 
      End If 
     '__________________________________________________________________________ 
     'Zone filter 
    ElseIf cboFilter.Text = "Zone and Book" Then 
     lblErrFilter.Visible = False 
     lblError.Visible = False 
     If drpYear.Text = "--Select--" Or drpMonth.Text = "--Select--" Or txtZone.Text = "--Select--" Or txtTop.Text = "" Then 
      If drpYear.Text = "--Select--" Then 
       lblErrYear.Visible = True 
      Else 
       lblErrYear.Visible = False 
      End If 
      If drpMonth.Text = "--Select--" Then 
       lblErrMonth.Visible = True 
      Else 
       lblErrMonth.Visible = False 
      End If 
      If txtZone.Text = "--Select--" Then 
       lblErrZone.Visible = True 
      Else 
       lblErrZone.Visible = False 
      End If 
      lblError.Visible = True 
      lblError.Text = "No value specified for the following parameter(s) *." 
     Else 
      lblErrYear.Visible = False 
      lblErrMonth.Visible = False 
      lblErrZone.Visible = False 
      Call bindData() 
      Call bindGrid() 
     End If 
    ElseIf cboFilter.Text = "Account Number" Then 
     If txtFrom.Visible = True And txtTo.Visible = True Then 
      If drpYear.Text = "--Select--" Or drpMonth.Text = "--Select--" Or txtFrom.Text = "" Or txtTo.Text = "" Then 
       If drpYear.Text = "--Select--" Then 
        lblErrYear.Visible = True 
       Else 
        lblErrYear.Visible = False 
       End If 
       If drpMonth.Text = "--Select--" Then 
        lblErrMonth.Visible = True 
       Else 
        lblErrMonth.Visible = False 
       End If 
       If txtFrom.Text = "" Then 
        lblErrR1.Visible = True 
       Else 
        lblErrR1.Visible = False 
       End If 
       If txtTo.Text = "" Then 
        lblErrR2.Visible = True 
       Else 
        lblErrR2.Visible = False 
       End If 
       lblError.Visible = True 
       lblError.Text = "No value specified for the following parameter(s) *." 
      Else 
       Call bindData() 
       Call bindGrid() 
      End If 
     Else 
      If drpYear.Text = "--Select--" Or drpMonth.Text = "--Select--" Or lstAcct.Items.Count = 0 Then 
       If drpYear.Text = "--Select--" Then 
        lblErrYear.Visible = True 
       Else 
        lblErrYear.Visible = False 
       End If 
       If drpMonth.Text = "--Select--" Then 
        lblErrMonth.Visible = True 
       Else 
        lblErrMonth.Visible = False 
       End If 
       If lstAcct.Items.Count = 0 Then 
        lblErrAcct.Visible = True 
       Else 
        lblErrAcct.Visible = False 
       End If 

       lblError.Visible = True 
       lblError.Text = "No value specified for the following parameter(s) *." 
      Else 
       lblErrYear.Visible = False 
       lblErrMonth.Visible = False 
       lblErrR1.Visible = False 
       lblErrR2.Visible = False 
       Call bindData() 
       Call bindGrid() 
      End If 
     End If 
    Else 
     If cboFilter.Text = "--Select--" Then 
      lblErrFilter.Visible = True 
     End If 
     lblError.Visible = True 
     lblError.Text = "No value specified for the following parameter(s) *." 
    End If 
    'Response.Redirect("~/Sites/CD/TopCon.aspx", True) 
End Sub 

,你可以看到我後,點擊過濾器按鈕執行完成。

這是我的頁面加載:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 


    If User.Identity.IsAuthenticated = False Then 
     Response.Redirect("/Default.aspx", True) 
    Else 
     If User.IsInRole("chicken") = True Or User.IsInRole("dog") = True Or User.IsInRole("cat") = True Then 
      If Not IsPostBack Then 
       maxTop = 10 
       txtTop.Text = maxTop 
       Call bindData() 
       Call bindGrid() 
       lblUser.Text = lblUser.Text & User.Identity.Name 
       lblIP.Text = lblIP.Text & GetIPAddress() 
       cboFilter.TabIndex = 0 
       Call fillYear() 
       Call fillDMZCombo() 
       Call fillZoneCombo() 
       Call fillType() 
      Else 
       *Call bindGrid()* 
      End If 
     Else 
      Response.Redirect("/Default.aspx", True) 
     End If 
    End If 

End Sub 

嗯,我知道爲什麼,當我點擊我的控制,它被設置在GridView刷新到自動回發是因爲我插在我裏面的Page_Load的bindGrid的原因其他。

它確實似乎是一個被動的代碼行。真正困擾我的是爲什麼當我查詢100條或更多條記錄時,我的過濾器按鈕中的bindGrid不會執行。

這裏是我的bindGrid代碼:

Public Sub bindGrid() 
    IpAdd = GetIPAddress() 
    xUser = User.Identity.Name 

    ShowCon = New SqlConnection("some data connection") 
    ShowCon.Open() 

    cmdShowCon = ShowCon.CreateCommand 
    cmdShowCon.CommandTimeout = 600 
    cmdShowCon.CommandText = "some simple select statement" 
    daShowCon.SelectCommand = cmdShowCon 
    dsShowCon.Clear() 
    daShowCon.Fill(dsShowCon, "someTable") 

    grdTopCon.DataSource = dsShowCon 
    grdTopCon.DataBind() 

End Sub 

任何幫助將非常感激。

回答

0

嘗試在btnFilter_Click中設置斷點以查看導致問題的原因。它可能是由它內部的算法或在Page_Load事件中引起的。