Lỗi the gridview gvkhachhang fired event pageindexchanging which wasnt handled năm 2024

When i use a sqldatasource to link a gridview the paging/sorting works all fine, but when i bind the grid with a dataset the following error appear´s The GridView 'GridView1' fired event PageIndexChanging which wasn't handled. What could be?

ASKER CERTIFIED SOLUTION

Lỗi the gridview gvkhachhang fired event pageindexchanging which wasnt handled năm 2024

skiltz


membership

This solution is only available to members.

To access this solution, you must be a member of Experts Exchange.

Start Free Trial

Lỗi the gridview gvkhachhang fired event pageindexchanging which wasnt handled năm 2024

rp

ASKER

Ok it´s working, and for sorting grid, which the code that I must put.

Hello,

please help. thanks.

When I run the program and I get this error message when I click on the second page.

The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.

I had page number on HTML like this:

PageSize="35" AllowPaging="True">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

lblMessage.Text = Session("message")  
Select Case lblMessage.Text  
    Case "Administrative/Computer"  
        GetFieldwork("QAdministrativeComputers_sp")  
    Case "Child/Youth"  
        GetFieldwork("QChildYouthService_sp")  
    Case "Counseling"  
        GetFieldwork("QCounselingServices_sp")  
    Case "Elderly"  
        GetFieldwork("QElderlyService_sp")  
    Case "Families/Couples"  
        GetFieldwork("QFamiliesCouples_sp")  
    Case "Health Issues"  
        GetFieldwork("QHealthIssues_sp")  
    Case "Other Programs"  
        GetFieldwork("QOtherPrograms_sp")  
    Case "No Background Clearance Required"  
        GetFieldwork("QBGClearance_sp")  
    Case "Person with Disabilities"  
        GetFieldwork("QPersonDisabilities_sp")  
    Case "Recreation Programs"  
        GetFieldwork("QRecreationPrograms_sp")  
    Case "Substance Abuse"  
        GetFieldwork("QSubstanceAbuse_sp")  
    Case "Tutoring Serives"  
        GetFieldwork("QTutoringServices_sp")  
    Case "Paid Internship"  
        GetFieldwork("QPaidInternship_sp")  
End Select  
End Sub Private Sub GetFieldwork(ByVal procedure As String)
Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DBHUSRConnectionString").ConnectionString)  
    Using cmd As SqlCommand = New SqlCommand(procedure, con)  
        cmd.CommandType = CommandType.StoredProcedure  
        Using sda As SqlDataAdapter = New SqlDataAdapter()  
            sda.SelectCommand = cmd  
            Dim dt As DataTable = New DataTable()  
            sda.Fill(dt)  
            GridView1.DataSource = dt  
            GridView1.DataBind()  
        End Using  
    End Using  
End Using  
End Sub

I am trying to implement paging on my gridview and I am getting the above error. I must not have something set right but I can't figure out what it is. I am reading my data into a DataTable and setting the GridView's DataSource to my datatable. I have a PageIndexChanging method for my gridview but it is not executing the code in the method. Here is what I have. Any help is appreciated!

GridView Markup

            
[/b]                
                
                
                
                    
                    
                    
                    
                    
                
            

Open in new window

Code Behind

static DataTable dtOpenTeams;
protected void Page_Load(object sender, EventArgs e)
{
    --- Only relevant code is shown ---
                if (Page.IsPostBack == false)
                {
                    // Get Open Teams
                    dtOpenTeams = EMPData.GetOpenTeams();
                    if (dtOpenTeams == null)
                    {
                        Master.showResults = true;
                        Master.resultsMessage = EMPData.ErrorMessage;
                        return;
                    }
                    // Bind Open Teams to gridview
                    gvOpenTeams.DataSource = dtOpenTeams;
                    gvOpenTeams.DataBind();
                }
}
        protected void gvOpenTeams_PageIndexChanging(Object sender, GridViewPageEventArgs e)
        {
            Master.showResults = false;
            // Cancel the paging operation if the user attempts to navigate to another page while the 
            // gridview control is in edit mode.
            if (gvOpenTeams.EditIndex != -1)
            {
                // Use the Cancel property to cancel the paging operation
                e.Cancel = true;
                // Display an error message
                int newPageNumber = e.NewPageIndex + 1;
                Master.resultsMessage = "Please update the record before moving to page " + newPageNumber.ToString();
                Master.showResults = true;
            }
            else
            {
                gvOpenTeams.DataSource = dtOpenTeams;
                gvOpenTeams.PageIndex = e.NewPageIndex;
                gvOpenTeams.DataBind();
            }
        }

Open in new window