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

can't page or sort

9 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ronen
Top achievements
Rank 1
Ronen asked on 07 Sep 2010, 10:44 AM
hi, when i try to sort or move page, the whole page is posted back and i get nothing in my grid.
when i refresh the page after that, i see it ok.
How do i prevent the posting back and how do i make it display the contents ok.
this is my grid:
<telerik:RadGrid ID="RadGridMailingList"
     Width="97%"
    AllowSorting="True" PageSize="15" AllowPaging="True"
    runat="server" Culture="he-IL" ShowStatusBar="True" GridLines="Vertical">
    <ExportSettings ExportOnlyData="True" FileName="MailingList"
        IgnorePaging="True" OpenInNewWindow="True">
    </ExportSettings>
    <MasterTableView Width="100%" Summary="RadGrid table" Dir="RTL"
        NoMasterRecordsText="אין רשומות להצגה." CommandItemDisplay="Top">
        <CommandItemSettings ExportToPdfText="יצוא ל PDF"
            ShowExportToCsvButton="True" ShowExportToExcelButton="True"
            ShowExportToWordButton="True" ExportToCsvText="יצוא ל CSV"
            ExportToExcelText="יצוא לאקסל" ExportToWordText="יצוא ל Word"
            RefreshText="רענון" ShowAddNewRecordButton="False" ShowRefreshButton="False"></CommandItemSettings>
        <PagerStyle PagerTextFormat="Change page: {4} &nbsp;עמוד <strong>{0}</strong> מתוך <strong>{1}</strong>, פריטים <strong>{2}</strong> עד <strong>{3}</strong> מתוך <strong>{5}</strong>." />
    </MasterTableView>
    <PagerStyle Mode="NextPrevAndNumeric" PageSizeLabelText="גודל עמוד:"
        VerticalAlign="Middle" />
    <StatusBarSettings LoadingText="טוען..." ReadyText="מוכן" />
</telerik:RadGrid>

also there is a bug in PageSizeLabelText, seems like the value can't be applied and the original "Page Size:" remains.

9 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 07 Sep 2010, 10:59 AM
Hello Ronen,

Can you elaborate on how it the problematic grid bound? Are you using simple data-binding or have bound the grid through its NeedDataSource event?

All the best,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ronen
Top achievements
Rank 1
answered on 08 Sep 2010, 08:05 AM
thanks, i'm using a datatable in this manner:
static string mConnectionString = ConfigurationManager.ConnectionStrings["conn"].ToString();

 

 

 

DataTable dtMailingList = new DataTable();

string select = "SELECT userid , FName as , LName as ,email as  FROM [USERS]";

 

protected void Page_Load(object sender, EventArgs e)

{

 

 

  if (!IsPostBack)

  {

   

fillDataTable(select);

 

    RadGridMailingList.DataSource = dtMailingList;

  }

}

 

public void fillDataTable(string query)

{

 

 

   SqlConnection conn = new SqlConnection(mConnectionString);

   

 

SqlDataAdapter adapter = new SqlDataAdapter();

 

   adapter.SelectCommand = 

 

new SqlCommand(query, conn);

 

   conn.Open();

 

 

   try
   {

      adapter.Fill(dtMailingList);

   }

 

   finally

 

   {
      conn.Close();

 

   }

}




0
Shinu
Top achievements
Rank 2
answered on 08 Sep 2010, 08:15 AM
Hello Rone,


When using simple data-binding, you will need to assign data-source and rebind the grid after each operation (paging, sorting, editing, etc.) like in MS DataGrid behavior.


I would suggest you to use Advanced Data Binding technique by attaching NeedDataSource event. Now in the NeedDataSource event, set the DataSource of grid as shown in the demo. The NeedDataSource event is especially designed to facilitate the work of the developers as you do not need to handle any sorting/paging/grouping/filtering/etc. commands manually.


-Shinu.
0
Ronen
Top achievements
Rank 1
answered on 08 Sep 2010, 09:10 AM
Thanks Shinu, I used advanced data binding and it works.

However , I have a button in my page which generates a new select query upon user filling checkboxes.

the button event should update the grid with the new datatable, however, i get an empty grid after clicking a button.:
public DataTable GetDataTable(string query)
        {
            SqlConnection conn = new SqlConnection(mConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = new SqlCommand(query, conn);
            DataTable myDataTable = new DataTable();
 
            conn.Open();
            try
            {
                adapter.Fill(myDataTable);
            }
            finally
            {
                conn.Close();
            }
 
            return myDataTable;
 
        }
        protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            RadGridMailingList.DataSource = GetDataTable(select);
        }

protected void Button1_Click(object sender, EventArgs e)
      {
          select = "SELECT userid, FName , LName,email  FROM [USERS]" +"Where...";
          RadGridMailingList.DataSource = GetDataTable(select);
      }

Also I still have  a full post back when paging or sorting, even though i am using  a radajaxmanager:
<telerik:RadAjaxManager ID="RadAjaxManager1"
            runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGridMailingList">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGridMailingList" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Sep 2010, 11:30 AM
Hello Ronen,

 You need to set the DataSource only in the NeedDataSource event of grid. In the button-click event handler, rebulid the query and Rebind the grid, which in turn call the NeedDataSource and populates the grid.

C#:
static string mConnectionString = ConfigurationManager.ConnectionStrings["conn"].ToString();
    string select = "SELECT userid , FName as , LName as ,email as  FROM [USERS]";
  
   public DataTable GetDataTable(string query)
   {
       SqlConnection conn = new SqlConnection(mConnectionString);
       SqlDataAdapter adapter = new SqlDataAdapter();
       adapter.SelectCommand = new SqlCommand(query, conn);
       DataTable myDataTable = new DataTable();
       conn.Open();
       try
       {
           adapter.Fill(myDataTable);
       }
       finally
       {
           conn.Close();
       }
       return myDataTable;
   }
   protected void RadGridMailingList_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
   {
       RadGridMailingList.DataSource = GetDataTable(select);
   }
   protected void Button1_Click(object sender, EventArgs e)
   {
       select = "SELECT userid, FName , LName,email  FROM [USERS]" + "Where...";
       RadGridMailingList.Rebind();
   }

Thanks,
Princy.
0
Ronen
Top achievements
Rank 1
answered on 08 Sep 2010, 11:54 AM
Now it works great, thanks Princy.
0
Ronen
Top achievements
Rank 1
answered on 08 Sep 2010, 12:11 PM
now another issue occured, i can't export the data from the grid. when i click one of the buttons in the command menu, the command menu dissappears and also the pager menu,

and nothing happens.
0
Accepted
Iana Tsolova
Telerik team
answered on 08 Sep 2010, 04:01 PM
Hello Ronen,

This behavior can be observed when you are trying to export ajaxified grid without disabling the ajax during export. Check out this online help topic and see if it helps.

All the best,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ronen
Top achievements
Rank 1
answered on 12 Sep 2010, 09:38 AM
Thanks, you are amazing.

I simply added :

 

 

ClientEvents-OnRequestStart="onRequestStart"
to my :

<
telerik:RadAjaxManager ID="RadAjaxManager1"

 

 

 

runat="server">

 


and added the javascript function:

 

 

function onRequestStart(sender, args)

 

{

 

 

if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||

 

args.get_eventTarget().indexOf(

 

"ExportToCsvButton") >= 0 ||

 

args.get_eventTarget().indexOf(

 

"ExportToWordButton") >= 0)

 

args.set_enableAjax(

 

false);

 

}


please, don't forget also to remember the bug about the PageSizeLabelText .


Tags
Grid
Asked by
Ronen
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Ronen
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or