This is a migrated thread and some comments may be shown as answers.

PageIndexChanged Does Not Fire when Row is Selected

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 15 Oct 2013, 09:09 PM
In ASP.NET, I have a webpage that uses a RadGrid (v.2013.2.717.40 Dev). The RadGrid has AllowPaging="true" and it uses OnPageIndexChanged. When I browse the webpage, the RadGrid has about 20 pages of data (with like 10 rows per page). When I click any of the page buttons below the grid (First Page, Previous Page, Next Page, or Last Page), the PageIndexChanged event will execute as expected. But if I first select one of the rows in the grid before clicking a page button, the PageIndexChanged will not execute.

For example, when I first browse my webpage, the grid is on page 1 of 20. If I click the Next Page button until I get to, let's say, page 3 of 20, the PageIndexChanged will execute each time I click the Next Page button. If I were to then select one of the rows within the grid, and click the Next Page button, the grid will navigate to the next page, but it will not execute the PageIndexChanged event. Once I am at the next page, if I click the Next Page button again (with no rows selected), the PageIndexChanged event will fire, unless I first select one of the rows in the grid; in which case, once a row is selected, the PageIndexChanged will not fire.

When I google on this, I find others having a similar problem, but not quite the same as I describe here. How do I make sure that PageIndexChanged will fire every time, regardless of whether I have (or don't have) a row selected in the grid?

Thank you

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Oct 2013, 09:16 AM
Hi Brain,

Here is a sample code snippet that i tried and it works fine PageIndexChanged fires when row is selected.If this doesn't help,please provide your full code snippet.

ASPX:
<telerik:RadGrid ID="myRadGrid" runat="server" AllowPaging="true" OnPageIndexChanged="myRadGrid_PageIndexChanged"
    OnNeedDataSource="myRadGrid_NeedDataSource">
    <MasterTableView DataKeyNames="CustomerID">
        <PagerStyle Mode="NextPrevAndNumeric" />
    </MasterTableView>
    <ClientSettings Selecting-AllowRowSelect="true">
    </ClientSettings>
</telerik:RadGrid>

C#:
protected void myRadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
    SqlConnection conn = new SqlConnection(ConnString);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand("SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address FROM Customers", conn);
 
    DataTable myDataTable = new DataTable();
 
    conn.Open();
    try
    {
        adapter.Fill(myDataTable);
    }
    finally
    {
        conn.Close();
    }
    myRadGrid.DataSource = myDataTable;
}
protected void myRadGrid_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
//Your code
}

Thanks,
Princy
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or