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

problem with radgrid in pageindexchange event

2 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Babu Puchakayala
Top achievements
Rank 1
Babu Puchakayala asked on 20 May 2010, 01:33 AM
Hi,

I Have radgrid in my page. When i turn off view state and in pageindexchanged event when click next page i am getting nothing. Simply a blank page.  But when i turn on view state I am getting data in next pages. Is there any way to get the data. I cant turn on the view state due to performance issue.   Please see the code below for the reference.

.aspx

        <telerik:RadGrid ID="RadGrid1" OnSortCommand="RadGrid1_SortCommand" OnPageIndexChanged="RadGrid1_PageIndexChanged"
            AllowSorting="True" PageSize="20" ShowGroupPanel="True" AllowPaging="True" AllowMultiRowSelection="True"
            AllowFilteringByColumn="true" AutoGenerateColumns="false" EnableViewState="false" runat="server" GridLines="None"
            OnItemUpdated="RadGrid1_ItemUpdated" OnDataBound="RadGrid1_DataBound">


aspx.cs


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
    }

    private void LoadData()
    {
        SqlConnection SqlConn = new SqlConnection("uid=tempuser;password=tempuser;data source=USWASHL10015\\SQLEXPRESS;database=CCOM;");
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = SqlConn;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "usp_testing";
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        RadGrid1.DataSource = ds;
        RadGrid1.DataBind();
        //RadGrid1.ClientSettings.AllowDragToGroup = true;
    }

    protected void RadGrid1_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)
    {
        //RadGrid1.Rebind();
        LoadData();
    }

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 May 2010, 07:06 AM
Hi Babu,

You can transform your code to take advantage of the advanced binding with NeedDataSource handling. Please, note that when using the NeedDataSource event RadGrid automatically accommodate the appropriate database operations without the need for you explicitly handle any paging, sorting, grouping, and so on. I tried the following way to achieve your scenario and its working well on my side.

aspx:
      
       
<telerik:RadGrid ID="RadGrid1"   
            OnSortCommand="RadGrid1_SortCommand" AllowSorting="True" 
            PageSize="20" ShowGroupPanel="True" AllowPaging="True" AllowMultiRowSelection="True" 
            AllowFilteringByColumn="true" AutoGenerateColumns="true" EnableViewState="false" 
            runat="server" GridLines="None" onneeddatasource="RadGrid1_NeedDataSource" 
            OnItemUpdated="RadGrid1_ItemUpdated" OnDataBound="RadGrid1_DataBound"
        </telerik:RadGrid> 

c#:
      
        private void LoadData() 
        { 
            SqlConnection SqlConn = new SqlConnection("uid=tempuser;password=tempuser;data source=USWASHL10015\\SQLEXPRESS;database=CCOM;"); 
            SqlCommand cmd = new SqlCommand(); 
            cmd.Connection = SqlConn
            cmd.CommandType = CommandType.StoredProcedure; 
            cmd.CommandText = "usp_testing"
            SqlDataAdapter da = new SqlDataAdapter(cmd); 
            DataSet ds = new DataSet(); 
            da.Fill(ds); 
            RadGrid1.DataSource = ds
        } 
 
        protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
        { 
            LoadData(); 
        } 

For more information about advanced binding please refer to Demo.

Regards,
Princy.

0
Babu Puchakayala
Top achievements
Rank 1
answered on 20 May 2010, 02:23 PM
Hi Princy,

Thanks a lot man. Its working. Could you tell me how it is working without pageindexchanged event? I am lil confused.

Anyway Thanks for your help.
Tags
Grid
Asked by
Babu Puchakayala
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Babu Puchakayala
Top achievements
Rank 1
Share this question
or