PageIndexChanged not firing

Discussion in 'ASP .Net Datagrid Control' started by TnCoder, Dec 19, 2005.

  1. TnCoder

    TnCoder Guest

    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"
     
    TnCoder, Dec 19, 2005
    #1
    1. Advertising

  2. TnCoder

    Elton Wang Guest

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

    HTH


    "TnCoder" <> wrote in message
    news:...
    > 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"
     
    Elton Wang, Dec 20, 2005
    #2
    1. Advertising

  3. TnCoder

    TnCoder Guest

    Bingo! that did the trick. Thanks for your help

    "Elton Wang" wrote:

    > Check if your datagrid's enableviewstate is false. Set it to true or when
    > postback rebind it's data source.
    >
    > HTH
    >
    >
    > "TnCoder" <> wrote in message
    > news:...
    > > 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"

    >
    >
    >
     
    TnCoder, Dec 21, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Strahl [MVP]

    PageIndexChanged not firing in DataGrid

    Rick Strahl [MVP], Nov 21, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    6,075
    rohit.shrivastava04@gmail
    Aug 11, 2009
  2. Will McKee
    Replies:
    0
    Views:
    2,361
    Will McKee
    Feb 23, 2004
  3. steve
    Replies:
    0
    Views:
    221
    steve
    Dec 16, 2003
  4. Will McKee
    Replies:
    8
    Views:
    211
    sharath GT
    Oct 9, 2004
  5. ajamrozek

    PageIndexChanged Not Firing

    ajamrozek, Mar 9, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    150
    ajamrozek
    Mar 9, 2005
Loading...

Share This Page