Hi Menthos,
I have added the following code for the handler, but I am still not getting anything. Would you be able to advise at all?
Protected Sub Button3_Click(ByVal sender AsObject,ByVal e AsEventArgs)Handles Button3.Click
Dim sqlConn AsNewSqlConnection
Dim sqlCmd AsNew SqlClient.SqlCommand
Dim sqlReader AsSqlDataReader
'If no values are supplied in the textbox, throw an error message.
If TextBox2.Text = ""Then
MsgBox("A centre code needs to be provided...")
EndIf
If TextBox2.Text <> ""Then
'Telling the system the location of the database.
sqlConn.ConnectionString = "server=servername;Initial Catalog=dbName;Trusted_Connection=yes"
'Here we are opening the connection to the database.
sqlConn.Open()
'This is to say that sqlCmd is a stored procedure.
sqlCmd.CommandType = System.Data.CommandType.StoredProcedure
'This is creating the command to execute the stored procedure based on the information given in the connection string.
sqlCmd = sqlConn.CreateCommand
'The command is triggered to execute the stored procedure which grabs all information for the specific centre.
sqlCmd.CommandText = "exec GetAllInformationKCSEBoxes '" & TextBox2.Text & "' "
'This will read the rows in the database.
sqlReader = sqlCmd.ExecuteReader()
GridView2.Columns.Clear()
'If there are rows of data that match are criteria
If (sqlReader.HasRows) Then
'The rows of data are grabbed for the specific centre from the database using the data reader.
GridView2.DataSource = sqlReader
GridView2.DataBind()
GridView2.Columns.Clear()
Else
MsgBox("The centre code provided does not exist...")
EndIf
'This is closing the connection to the database once we have finished with it.
sqlConn.Close()
'This is to clear the list of items out of the GridView box.
EndIf
End Sub
Property GridViewSortDirection() AsString
Get
If IsNothing(ViewState.Item("GridViewSortDirection"))Then
Return"desc"
EndIf
Return ViewState.Item("GridViewSortDirection")
EndGet
Set(ByVal Value AsString)
ViewState.Item("GridViewSortDirection") = Value
EndSet
EndProperty
Function GetSortDirection() AsString
Dim GridViewSortDirectionNew AsString
SelectCase GridViewSortDirection
Case"DESC"
GridViewSortDirectionNew = "ASC"
Case"ASC"
GridViewSortDirectionNew = "DESC"
Case Else
GridViewSortDirectionNew = "DESC"
EndSelect
GridViewSortDirection = GridViewSortDirectionNew
Return GridViewSortDirectionNew
EndFunction
ProtectedSub gv_PageIndexChanging1(ByVal sender AsObject,ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
GridView2.PageIndex = e.NewPageIndex
GridView2.DataBind()
EndSub
ProtectedSub GridView_Sorting1(ByVal sender AsObject,ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs)
Dim myPageIndex AsInteger = GridView2.PageIndex
Dim mySortdirection AsString = GetSortDirection()
Dim dv AsNewDataView()
dv.Table = GridView2.DataSource
dv.Sort = e.SortExpression & " " & mySortdirection
GridView2.DataSource = dv
GridView2.DataBind()
GridView2.PageIndex = myPageIndex
EndSub
</script>
For my GridView:
<asp:GridViewID="GridView2"runat="server"Height="143px"AllowSorting="true"OnSorting="GridView_Sorting1"
Many thanks,
Dan