PageIndexChanged not firing

T

TnCoder

I'm new to web app. programming so please bare with me. I have a datagrid
that has several items. The allowpaging is set to true. The gird initially
loads just fine, but if I click on the next page, (or any other) the grid
disappears. I've put stops on the code in the PageIndexChanged event, but it
never hits. Any ideas? The relevant code is included below:

Public Function LoadGrid(ByVal LocId As Integer, ByVal Index As Integer)
Dim Sql As String
Dim Dt As New DataTable
Dim C As Long
Dim Ds As DataSet
Dim Dv As DataView
Dim X As Integer
Dim TableStyle As New DataGrid

Sql = "SELECT Encounter.RoomNum,encounter.complete," & _
"(MR_Main.Patient_Name_Last + ','+
MR_Main.Patient_Name_First + ' ' + MR_Main.Patient_Name_Middle) as PName," & _

"Encounter.FacilityRec_Num,Encounter.Encounter_Num,provider_list.shortname,"
& _
"Encounter.Facility_Code,
encounter.admit_Date,encounter.DC_date, encounter.attending_MD FROM
encounter,mr_main,provider_list " & _
" WHERE ((Encounter.Complete = 'N') AND
(Encounter.Facility_Code=" & _
LocId & ") and (encounter.attending_md =
provider_list.providernum)and (encounter.medrecnum = mr_main.medrec_num)) " &
_
" order by Encounter.RoomNum"
Ds = New DataSet
Dim dta As New SqlClient.SqlDataAdapter(Sql, SqlConnection1)
dta.Fill(Ds)

dgPatients.DataSource = Ds

Dv = New DataView(Ds.Tables(0))
Dt = Ds.Tables(0)
C = Dt.Rows.Count()
Dim Dc1 As New BoundColumn
Dim Dc2 As New BoundColumn
Dim Dc3 As New BoundColumn
Dim Dc4 As New BoundColumn
Dim Dc5 As New BoundColumn
Dim Dc6 As New ButtonColumn
Dim Dc7 As New ButtonColumn
Dim Dc8 As New ButtonColumn

Dc1.DataField = "RoomNum"
Dc1.HeaderText = "Room#"
dgPatients.Columns.Add(Dc1)

Dc2.DataField = "PName"
Dc2.HeaderText = "Patient Name"
Dc2.ItemStyle.Width.Pixel(200)
dgPatients.Columns.Add(Dc2)

Dc3.DataField = "Admit_Date"
Dc3.HeaderText = "Admit Date"
Dc3.ItemStyle.Width.Pixel(400)
dgPatients.Columns.Add(Dc3)

Dc4.DataField = "DC_Date"
Dc4.HeaderText = "Discharge Date"
dgPatients.Columns.Add(Dc4)

Dc5.DataField = "shortname"
Dc5.HeaderText = "Attending Md"
dgPatients.Columns.Add(Dc5)


Dc6.ButtonType = ButtonColumnType.LinkButton
Dc6.DataTextField = "Complete"
Dc6.HeaderText = "Complete"
dgPatients.Columns.Add(Dc6)

Dc7.ButtonType = ButtonColumnType.PushButton
Dc7.CommandName = "Charges"
Dc7.HeaderText = "Get Charges"
Dc7.Text = "Charges"
dgPatients.Columns.Add(Dc7)

Dc8.ButtonType = ButtonColumnType.PushButton
Dc8.CommandName = "Edit"
Dc8.HeaderText = "Edit Charges"
Dc8.Text = "Edit"
dgPatients.Columns.Add(Dc8)
dgPatients.VirtualItemCount = 10
dgPatients.DataBind()
dgPatients.CurrentPageIndex = Index
dgPatients.Visible = True

End Function

Public Sub dgPatients_PageIndexChanged(ByVal source As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Call LoadGrid(DDFacility.SelectedValue, e.NewPageIndex)
End Sub

The code behind is:
asp:datagrid id="dgPatients" runat="server"
AutoGenerateColumns="False" onpageindexchanged="dgPatients_PageIndexChanged"
AllowPaging="True"
 
E

Elton Wang

Check if your datagrid's enableviewstate is false. Set it to true or when
postback rebind it's data source.

HTH
 
T

TnCoder

Bingo! that did the trick. Thanks for your help

Elton Wang said:
Check if your datagrid's enableviewstate is false. Set it to true or when
postback rebind it's data source.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top