Sub Page_Load(...)
If Not IsPostBack Then
BindData()
End If
gvCustomers.AllowPaging = False
BindData()
lblResult.Text = gvCustomers.Rows.Count.ToString & " records found "
gvCustomers.AllowPaging = True
BindData()
End Sub
Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClear.Click
' Simple clean up text to return the Gridview to it's default state
searchBox.Text = ""
SearchString = ""
BindData()
End Sub
然后在gridview标记上:
<asp:Label ID="lblResult" style ="font-weight:bold; " runat="server"
CssClass="style26"></asp:Label>
... another markup goes here ...
<asp:button ID="btnClear" Text="Reset" runat="server" />
我们想做的是在页面加载时在 gridview 上显示记录总数。就页面加载而言,这可以正常工作。当您搜索记录时,它会显示找到的正确记录数。
现在是问题部分。如果单击重置按钮控件,gridview 应默认返回记录总数。当您按一次重置按钮时,它不会重置为原始总数。
在页面重新加载 gridview 上的记录总数之前,您必须按两次重置按钮。
任何想法如何解决这个问题,以便在第一次按下重置按钮时重新加载?非常感谢提前
Private Sub BindData()
Dim strSearch As String
'Protect against SQL Injection
strSearch = Replace(searchBox.Text, "'", "''", 1, -1, 1)
Dim query As String = "SELECT r.RoleId,l.LoginId, l.fullname,l.UserName,r.UserRoles FROM tblLogin l Inner Join tblRoles r on l.rights = r.roleId WHERE l.fullname LIKE '%" & strSearch & "%' "
Dim cmd As New SqlCommand(query)
gvCustomers.DataSource = GetData(cmd)
gvCustomers.DataBind()
End Sub