这是一个包含一个文本框,一个按钮和一个限制为10行的gridview的表单,很好。 当程序运行时,在文本框上键入内容,单击按钮,中提琴显示10行和7页。 当我点击第2页或第3页或第4页时......网格视图保持不变。
如果在单击第2页然后单击按钮后,Gridview将显示正确的信息。其他页面也是如此。
为什么说到Render,Gridview1没有任何行?
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim i = 0
While (i < GridView1.Rows.Count)
ClientScript.RegisterForEventValidation(GridView1.UniqueID, "select$" + i.ToString())
i += 1
End While
MyBase.Render(writer)
End Sub
Protected Sub gridview1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Dim rowID As String = "row" + e.Row.RowIndex.ToString
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("id", rowID)
e.Row.Attributes.Add("onclick", "highlightRow('" & rowID & "','" & e.Row.CssClass & "');" + ClientScript.GetPostBackClientHyperlink(Me.GridView1, "select$" + e.Row.RowIndex.ToString()))
If (e.Row.RowState = DataControlRowState.Alternate) Then
e.Row.CssClass = "alternate"
Else
e.Row.CssClass = "normal"
End If
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Attributes.Add("onkeyup", "searching()")
TextBox1.Focus()
End Sub
我相信我遗漏了一些非常基本的东西,但我不知道它是什么。 我一点帮忙?
感谢您的关注。
这是html ...
<asp:GridView ID="GridView1"
runat="server" AllowPaging="True"
OnPageIndexChanging="gv1_pageindexchanging"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
HeaderStyle-CssClass="titulo"
OnRowDataBound="gridview1_RowDataBound"
OnSelectedIndexChanged="gridview1_selectedindexchanged"
CssClass="gridview1"
SelectedIndex="0">
<Columns>
<asp:BoundField DataField="tipo"
HeaderText="tipo"
SortExpression="tipo" />
<asp:BoundField DataField="begyear"
HeaderText="begyear"
SortExpression="begyear" />
<asp:BoundField DataField="endyear"
HeaderText="endyear"
SortExpression="endyear" />
<asp:BoundField DataField="marker"
HeaderText="marker"
SortExpression="marker" />
<asp:BoundField DataField="mtl"
HeaderText="mtl"
SortExpression="mtl" />
<asp:BoundField DataField="desc"
HeaderText="desc"
SortExpression="desc" />
<asp:BoundField DataField="yards"
HeaderText="yards"
SortExpression="yards" />
<asp:BoundField DataField="model"
HeaderText="model"
SortExpression="model" />
<asp:BoundField DataField="style"
HeaderText="style"
SortExpression="style" />
<asp:BoundField DataField="drive"
HeaderText="drive"
SortExpression="drive" />
<asp:BoundField DataField="notes"
HeaderText="notes"
SortExpression="notes" />
<asp:BoundField DataField="F12"
HeaderText="F12"
SortExpression="F12" />
<asp:BoundField DataField="F13"
HeaderText="F13"
SortExpression="F13" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server" ConnectionString="<%$ ConnectionStrings:carpetsdbConnectionString %>">
</asp:SqlDataSource>
<asp:ScriptManager ID="ScriptManager1"
runat="server" EnablePartialRendering="true">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1"
runat="server">
<ContentTemplate>
<asp:Image ID="Image1"
runat="server" BorderColor="#FFCCFF"
CssClass="resize"
BorderStyle="Double" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="GridView1"
EventName="SelectedIndexChanged">
</asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
</form>