我目前正在开展一个项目。我突然偶然发现了一个真正引起我大脑烦恼的问题。我有一个函数,它将数据库中表的内容显示到gridview,我将其命名为bindGrid。当我查询50到90条记录时,它工作正常。但是,当我查询100条或更多条记录时,gridview不会显示记录,直到我更改设置为autopostback的下拉框的值。
以下是代码示例:
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
我知道当我点击设置为autopostback的控件时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 :(得分:0)
尝试在btnFilter_Click
中设置断点,以查看导致问题的原因。它可能是由其内部的算法引起的,也可能是由Page_Load
事件引起的。