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

How to do paging in rad grid

5 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 21 Sep 2012, 12:56 PM
How to do paging in rad grid with PagerStyle Mode="NextPrevAndNumeric"
please reply Thanks

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Sep 2012, 01:03 PM
Hi,

In order to implement advanced features in RadGrid like paging, make sure that grid is binded using its NeedDataSource event. Here is the sample code.
aspx:
<telerik:RadGrid  ID="RadGrid1"  runat="server" AllowPaging="true" AutoGenerateColumns="false"    PageSize="4" onneeddatasource="RadGrid1_NeedDataSource">
  <PagerStyle Mode="NextPrevAndNumeric" />
    . . .        
</telerik:RadGrid>
Also take a look in to the following demo.
Grid / Basic Paging

Thanks,
Shinu.
0
Swapnil
Top achievements
Rank 1
answered on 21 Sep 2012, 01:09 PM
Hey i am new to telerik
i dont know what is needdatasource event and how to use it can u please explain
Thank U
0
Accepted
Shinu
Top achievements
Rank 2
answered on 24 Sep 2012, 05:18 AM
Hi,

The NeedDataSource event fires in the following cases as explained in this documentation.

  • Immediately after On_Load if the grid has not yet been data-bound and there is no ViewState data. This means that if MasterTableView.EnableViewState has been set to false, grid will bind each time the page loads, not only the first time.

  • When a paging operation occurs.

  • When a sorting operation occurs.

  • When an edit command is fired.

    You can attach this event and then bind the gird as shown below.
    aspx:

    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="false" AllowFilteringByColumn="true"  AllowSorting="true"  OnNeedDataSource="RadGrid2_NeedDataSource">
        <MasterTableView>
             <Columns>
              <telerik:GridBoundColumn DataField="LastName" UniqueName="LastName" HeaderText="LastName"></telerik:GridBoundColumn>
            </Columns>
         </MasterTableView>
    </telerik:RadGrid>

C#:
protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
        SqlConnection con1 = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString3"].ConnectionString);
        SqlCommand cmd = new SqlCommand("SELECT top 5 * FROM [Orders]", con1);
        SqlDataAdapter ad = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        ad.Fill(ds);
        RadGrid2.DataSource = ds;
}

Thanks,
Shinu.
0
Swapnil
Top achievements
Rank 1
answered on 24 Sep 2012, 06:28 AM
Paging is done correctely
but another issue arises for this the code isnamespace Telerik
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        Entity ent = new Entity();
        EMPLOYEE emp = new EMPLOYEE();
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        public void BindGrid()
        {
           
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            ent.Insert_emp(txtname.Text, txtaddress.Text, Convert.ToInt32(txtdeptid.Text));
            ent.SaveChanges();
            //BindGrid();
            gv1.DataBind();
        }

        protected void gv1_NeedDataSource(object sender, Web.UI.GridNeedDataSourceEventArgs e)
        {
            //BindGrid();
            var query = from employee in ent.EMPLOYEEs
                        select new
                        {
                            ID = employee.ID,
                            NAME = employee.NAME,
                            ADDRESS = employee.ADDRESS,
                            DEPTID = employee.DEPTID
                        };
            gv1.DataSource = query;
            //gv1.DataBind();
        }
    }
}

previouslu i had method BindGrid() to load record after addition quickly but now i dont have that method i moved that code into your event now how can i insert data and load grid without postback
please help.
0
Swapnil
Top achievements
Rank 1
answered on 24 Sep 2012, 07:02 AM
Your solution is absolutely correct
works great
thanks for the help Shinu
Tags
Grid
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Swapnil
Top achievements
Rank 1
Share this question
or