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

How to Set Paging

3 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DEBAL
Top achievements
Rank 1
DEBAL asked on 20 Apr 2012, 03:58 PM
Hi Support

In Radgrid for asp.net , I have large number of records in Grid and there is radio button along side with every row , I also use paging and page size = 20, now how can I know which row number will be if radio button number choose by user  or suppose selected RadioButton is 80 then how can i show the radgrid paging in that page where the radiobutton is existed . By default paging starts from 1 but I need to show that page where user choose may be the page is in 8th number paging ,

See the code:
Private void Method(int number)
{
RadGrid1.Allowpaging = false;
 RadGrid1.ReBind();
 foreach (GridDataItem item in grid1.Items)
 {
  RadioButton btn = (RadioButton)item.FindControl("radiobutton1");
  string value = item.GetDataKeyValue("Questionnumber").ToString(); 
    if( value == Questionnumber)
          {
                 btn.checked = true;
RadGrid1.CurrentpageIndex = questionnumber;
}
RadGrid1.Allowpaging = true;
RadGrid1.PageSize = 20;
 RadGrid1.ReBind(); // if I write this then my Radio Button selected is not show and if I not write then paging is not show

Any suggestion will be helpful or any demo project

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Apr 2012, 05:26 AM
Hello DEBAL,

Please check below code snippet.
// By below code you can set pahe number 8 on button click
    protected void Button1_Click1(object sender, EventArgs e)
    {
        RadGrid1.MasterTableView.CurrentPageIndex = 3;
        RadGrid1.Rebind();
    }


Thanks,
Jayesh Goyani
0
DEBAL
Top achievements
Rank 1
answered on 21 Apr 2012, 04:01 PM
Hi
Thanks for your reply , you write is through hardcoded but I need like that

Private void Method(int number)
{
RadGrid1.Allowpaging = false;
 RadGrid1.ReBind();
 foreach (GridDataItem item in grid1.Items)
 {
  RadioButton btn = (RadioButton)item.FindControl("radiobutton1");
  string value = item.GetDataKeyValue("Questionnumber").ToString(); 
           if( value == Questionnumber)
          {
                    btn.checked = true;

RadGrid1.MasterTableView.CurrentPageIndex = 3;

// see ,here is also one problem : I write it 3 but it should be like that
// which radiobutton is selected I need to find the current page Index of that page where the selected radiobutton row is exist .
// suppose I know in Current pageIndex 3 , my desired item row is exists so I write this , so the paging will be selected in 3 but I need
// to do it though code , any Idea pl
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Apr 2012, 08:02 AM
Hello DEBAL,

Please check below code snippet.
.aspx
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
         AutoGenerateColumns="false"
         AllowPaging="true" PageSize="3">
        <MasterTableView DataKeyNames="ID">
            <Columns>
                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>
            </Columns>
           
        </MasterTableView>
    </telerik:RadGrid>


.aspx.cs
{
        dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name ="Name2"},
                new { ID = 3, Name ="Name2"},
                new { ID = 4, Name ="Name2"},
                new { ID = 5, Name ="Name2"},
                new { ID = 6, Name ="Name2"},
                new { ID = 7, Name ="Name2"},
                new { ID = 8, Name ="Name2"},
                new { ID = 9, Name ="Name2"},
                new { ID = 10, Name ="Name2"},
                new { ID = 11, Name ="Name2"},
                new { ID = 12, Name ="Name2"},
            };
 
        RadGrid1.DataSource = data;
    }
 
 
protected void Button1_Click(object sender, EventArgs e)
    {
        double count = 0.00;
 
        int pagesize = RadGrid1.PageSize;
 
        RadGrid1.AllowPaging = false;
        RadGrid1.Rebind();
 
 
        foreach (GridDataItem item in RadGrid1.Items)
        {
            count++;
 
            if (item["ID"].Text == "7")
            {
                break;  
            }
        }
 
        double temp = count / pagesize;
        int temp1 = Convert.ToInt32(count) / pagesize;
 
        RadGrid1.AllowPaging = true;
        RadGrid1.MasterTableView.CurrentPageIndex = temp == Convert.ToDouble(temp1) ? temp1 - 1 : temp1;
        RadGrid1.Rebind();
 
    }


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