Please help i am trying to load data to my gridview
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=UNIFORMPROJVB
StackTrace: at UNIFORMPROJVB.Newsearchdata.OnRowDataBound(Object sender, GridViewRowEventArgs e) in C:\Users\Makumbi\source\repos\UNIFORMPROJVB\UNIFORMPROJVB\Forms\Newsearchdata.aspx.vb:line 80
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
'If e.Row.RowType = DataControlRowType.DataRow AndAlso Stockbooks.EditIndex = e.Row.RowIndex Then
If (e.Row.RowType = DataControlRowType.DataRow) Then
'Find the DropDownList in the Row
Dim ddlCountries As DropDownList = CType(e.Row.FindControl("ddlclasses"), DropDownList)
ddlCountries.DataSource = GetData("SELECT DISTINCT(Class)as classr FROM Classes")
ddlCountries.DataTextField = "Classr"
ddlCountries.DataValueField = "Classr"
ddlCountries.DataBind()
'Add Default Item in the DropDownList
ddlCountries.Items.Insert(0, New ListItem("Please select"))
'Select the Country of Customer in DropDownList
Dim country As String = CType(e.Row.FindControl("Lblclasses"), Label).Text
If country = "" Then
Exit Sub
Else
ddlCountries.Items.FindByValue(country).Selected = True
End If
End If
End Sub
Private Sub BindGrid()
Dim cmd As New SqlCommand("SELECT Name,class as Classr,class,stream, House, ACNOS,admno,sex,STDTYPE,Autofield FROM STUDENT")
Stockbooks.DataSource = Me.ExecuteQuery(cmd, "SELECT")
Stockbooks.DataBind()
Stockbooks.UseAccessibleHeader = True
Stockbooks.HeaderRow.TableSection = TableRowSection.TableHeader
End Sub