Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submitting data to a datagrid then page through records

Status
Not open for further replies.

Maximus007

Technical User
Jul 26, 2004
248
US
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




 
Yes! I am able to retrieve the data but unable to page through the records.
 
What do you have in your PageIndexChanged event?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
And just to clarify my above statement, I mean in the HTML have you set the PageIndexChanged event to point at the relevant procedure? Maybe if you post your HTML for the DataGrid it will help?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Oh, and I notice you don't set the DataSource in your NewPage event...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top