Maximus007
Technical User
I have a drop down menu that populates data then the user selects a start date and an end date. Then he/she hits the submit button to view the data in the datagrid and they are able to page the records. I am having problem paging through the record. Can I achieve this in one page or would it have to two pages. It you do know of a better way to accomplish this please assist me. Here's what I have.
Thank you
Code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
StartRadio.Checked = True
Calendar1.SelectedDate = Now()
txtStart.Text = Calendar1.SelectedDate
Calendar1.TodaysDate = Calendar1.SelectedDate
'fill the dropdown menu
Dim cmdTech As New SqlCommand("Select Fname from LoginToServer", SqlConnection1)
Dim DrTech As SqlDataReader
SqlConnection1.Open()
DrTech = cmdTech.ExecuteReader()
dpName.DataSource = DrTech
dpName.DataTextField = "Fname"
dpName.DataBind()
DrTech.Close()
SqlConnection1.Close()
End If
End Sub
Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
If StartRadio.Checked = True Then
txtStart.Text = Calendar1.SelectedDate
Else
txtEnd.Text = Calendar1.SelectedDate
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strTech = (dpName.SelectedItem.Text)
Dim strStart = (txtStart.Text)
Dim strEnd = (txtEnd.Text)
Dim ObjConnection As SqlConnection
Dim ObjCommand As SqlCommand
Dim ObjAdapter As SqlDataAdapter
Dim ObjDataSet As DataSet
Dim strSelect As String
'Connection()
ObjConnection = New SqlConnection("Server=N/A;UID=N/A;PWD=N/A;Database=N/A")
'Querying the database
strSelect = ("Select ServerID as[Server ID], " & _
"ServerName as[Server Name], Task as[Task], DiskSpace as[Disk Space], " & _
"EventViewer as [Event Viewer], Hardware as [Hardware], Patches as [Patches], " & _
"BackupServer as [Backup Server], BackupJob as [Backup Job],Tech as [Tech], " & _
"DateEntered as[Date Entered], ServerComments as[Comments] from N/A where DateEntered Between '" & strStart & "' AND '" & strEnd & "' And Tech='" & strTech & "'")
ObjCommand = New SqlCommand(strSelect, ObjConnection)
'Get a DataSet to bind the DataGrid to
ObjAdapter = New SqlDataAdapter(ObjCommand)
ObjDataSet = New DataSet
ObjAdapter.Fill(ObjDataSet)
' DataBind DG to DS
DataGrid1.DataSource = ObjDataSet
DataGrid1.DataBind()
ObjConnection.Close()
End Sub
Sub NewPage(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
DataGrid1.DataBind()
DataGrid1.CurrentPageIndex = e.NewPageIndex
End Sub
Thank you
Code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
StartRadio.Checked = True
Calendar1.SelectedDate = Now()
txtStart.Text = Calendar1.SelectedDate
Calendar1.TodaysDate = Calendar1.SelectedDate
'fill the dropdown menu
Dim cmdTech As New SqlCommand("Select Fname from LoginToServer", SqlConnection1)
Dim DrTech As SqlDataReader
SqlConnection1.Open()
DrTech = cmdTech.ExecuteReader()
dpName.DataSource = DrTech
dpName.DataTextField = "Fname"
dpName.DataBind()
DrTech.Close()
SqlConnection1.Close()
End If
End Sub
Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
If StartRadio.Checked = True Then
txtStart.Text = Calendar1.SelectedDate
Else
txtEnd.Text = Calendar1.SelectedDate
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strTech = (dpName.SelectedItem.Text)
Dim strStart = (txtStart.Text)
Dim strEnd = (txtEnd.Text)
Dim ObjConnection As SqlConnection
Dim ObjCommand As SqlCommand
Dim ObjAdapter As SqlDataAdapter
Dim ObjDataSet As DataSet
Dim strSelect As String
'Connection()
ObjConnection = New SqlConnection("Server=N/A;UID=N/A;PWD=N/A;Database=N/A")
'Querying the database
strSelect = ("Select ServerID as[Server ID], " & _
"ServerName as[Server Name], Task as[Task], DiskSpace as[Disk Space], " & _
"EventViewer as [Event Viewer], Hardware as [Hardware], Patches as [Patches], " & _
"BackupServer as [Backup Server], BackupJob as [Backup Job],Tech as [Tech], " & _
"DateEntered as[Date Entered], ServerComments as[Comments] from N/A where DateEntered Between '" & strStart & "' AND '" & strEnd & "' And Tech='" & strTech & "'")
ObjCommand = New SqlCommand(strSelect, ObjConnection)
'Get a DataSet to bind the DataGrid to
ObjAdapter = New SqlDataAdapter(ObjCommand)
ObjDataSet = New DataSet
ObjAdapter.Fill(ObjDataSet)
' DataBind DG to DS
DataGrid1.DataSource = ObjDataSet
DataGrid1.DataBind()
ObjConnection.Close()
End Sub
Sub NewPage(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
DataGrid1.DataBind()
DataGrid1.CurrentPageIndex = e.NewPageIndex
End Sub