GridView1我正在尝试从这里切换我在gridview上的代码:
<asp:SqlDataSource ID="dsPar" runat="server" ConnectionString="<%$ ConnectionStrings:connstring %>"
SelectCommand="SELECT ID, FileNumber, address, phone from myTable ORDER BY ID" FilterExpression="ID like '%{0}%'">
<FilterParameters>
<asp:ControlParameter Name="StreetSrch" ControlID="searchBox" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
对此:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strQuery As String = "SELECT ID, FileNumber, address, Phone from MyTable WHERE Id LIKE '%@strSearch%' ORDER BY Id"
Dim cmd As New SqlCommand(strQuery)
Dim dt As DataTable = GetData(cmd)
Dim CheckBoxArray As ArrayList
If ViewState("CheckBoxArray") IsNot Nothing Then
CheckBoxArray = DirectCast(ViewState("CheckBoxArray"), ArrayList)
Else
CheckBoxArray = New ArrayList()
End If
If Not IsPostBack Then
Gridview1.DataBind()
Dim CheckBoxIndex As Integer
Dim CheckAllWasChecked As Boolean = False
Dim chkAll As CheckBox = DirectCast(GridView1.HeaderRow.Cells(0).FindControl("chkAll"), CheckBox)
rest of code....
End If
End Sub
最后,下面是标记的快照:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True"
OnPageIndexChanging = "OnPaging" HeaderStyle-CssClass = "header" Font-Size = "10pt"
AlternatingRowStyle-BackColor = "#C2D69B" OnRowDataBound = "RowDataBound" AllowSorting="true"
PageSize="20" CssClass="Gridview"
GridLines="None">
我正在"Object reference not set to an instance of an object."
以下行:
第 44 行:Dim chkAll As CheckBox = DirectCast(GridView1.HeaderRow.Cells(0).FindControl("chkAll"), CheckBox)
知道如何解决这个问题吗?
代码很长,我不想在这里全部发布。如果需要,我可以发布更多。