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

Paging is not working in radgrid

5 Answers 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
avinash
Top achievements
Rank 1
avinash asked on 19 May 2014, 10:04 AM
hi,

I am trying to implement paging in rad grid , but when i click from 1st page to 2nd radgrid is not dispalying any data.

what i  am doing iin aspx page below:-

  <form id="form1" runat="server">
    <div>
    <telerik:RadGrid ID="radgrdidemo"  OnNeedDataSource="RadGrid1_NeedDataSource"  AutoGenerateColumns="false" runat="server" >
   <MasterTableView  AllowPaging="true" AutoGenerateColumns="false"> 
    <Columns>
    <telerik:GridBoundColumn DataField="Inno_ID_Key" HeaderText="userid" Visible="true">
                                </telerik:GridBoundColumn>
   </Columns>

</MasterTableView>
    </telerik:RadGrid>
    </div>
    <div>
    <telerik:RadAjaxLoadingPanel ID="LP1" runat="server"></telerik:RadAjaxLoadingPanel>
    
    </div>
    <div>
    <telerik:RadAjaxManager runat="server">
    <AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="radgrdidemo">
    <UpdatedControls>
    
    <telerik:AjaxUpdatedControl ControlID="radgrdidemo" LoadingPanelID="LP1" />
    </UpdatedControls>

    </telerik:AjaxSetting>
    </AjaxSettings>
    </telerik:RadAjaxManager>
    </div>
    <div>
    <telerik:RadScriptManager runat="server">
    </telerik:RadScriptManager>
    </div>
    </form>

and i am binding grid in page load 

public partial class WebForm5 : System.Web.UI.Page
    {
        public SqlDataReader dr;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            var conString = System.Configuration.ConfigurationManager.ConnectionStrings["Amscan-ProdConnectionString"];
            string strConnString = conString.ConnectionString;
            SqlConnection sqlCon = new SqlConnection(strConnString);
            sqlCon.Open();
            SqlCommand CMD = new SqlCommand(" SELECT Inno_ID_Key from DimAhiEvent ", sqlCon);

            dr = CMD.ExecuteReader();
      
            radgrdidemo.DataSource = dr;
            radgrdidemo.DataBind();
           



        }
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            radgrdidemo.DataSource = dr;
        }
    }
and one thing there i see that when i am going from 1st pge to 2nd whole page loads again that i want to avoid .









5 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 19 May 2014, 10:42 AM
Hello,

Please try with  the below code snippet.

public SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
 
 
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    var conString = System.Configuration.ConfigurationManager.ConnectionStrings["Amscan-ProdConnectionString"];
    string strConnString = conString.ConnectionString;
    SqlConnection sqlCon = new SqlConnection(strConnString);
    sqlCon.Open();
    SqlCommand CMD = new SqlCommand(" SELECT Inno_ID_Key from DimAhiEvent ", sqlCon);
 
    dr = CMD.ExecuteReader();
 
    radgrdidemo.DataSource = dr;
}


Thanks,
Jayesh Goyani
0
avinash
Top achievements
Rank 1
answered on 19 May 2014, 11:47 AM
Hi Jayesh,

the above solution is working perfectly but there is always a page Postback whenever we are changing the index of paging , any solution or approach for that

0
Princy
Top achievements
Rank 1
answered on 19 May 2014, 12:08 PM
Hi Avinash,

When binding the grid with NeedDataSource event you donot have to bind it again in the PageLoad. Please take a look at this documentation for more details.
Advanced Data-binding (Using NeedDataSource Event)

Thanks,
Princy
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 21 May 2014, 05:58 AM
Hello Avinash,

Posting is needed in server side binding. But you can ajaxify your radgrid.

UpdatePanel :
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                  // Your Radgrid markup code
            </ContentTemplate>
        </asp:UpdatePanel>

RadAjaxManager: Please add this code above your radgrid.

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
</telerik:RadAjaxManager>


Thanks,
Jayesh Goyani
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 21 May 2014, 06:00 AM
Hello,

I have changed the ID in above code snippet.

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="radgrdidemo">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="radgrdidemo"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
</telerik:RadAjaxManager>

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