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

RadGrid paging and sorting: not working when i change the dataset SelectCommand

1 Answer 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Emanuele
Top achievements
Rank 1
Veteran
Emanuele asked on 08 Jan 2015, 12:42 PM
Hi, I have a problem with sorting and pagination in a radgrid.It is connected to a DataSource (dsMAV). If i set the SelectCommand in declarative mode then paging and sorting work.
If I declare the SelectCommand as empty string and then modify it at runtime when the page loads:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dsMAV.SelectCommand = "SELECT IDRendicontazione, [Matricola], [CodiceFiscale], [Nominativo], [Importo], [F_Scrigno], [DataIncasso], [DataContabile], Disposizione, Transazione, [Causale], [NProvvisorio], [MavKey] FROM [Rendicontazioni]";
}
}

the first load works fine but pagination and sorting don't work, returning an empty result set.
If i take the assignment out of the if then it works. But I do not understand why in the first case doesn't work because the viewstate is enabled as default.
I need to understand this because the next step is to build a filter using a form and not the radgrid filter and I must change at runtime the SelectCommand.

Thanks a lot

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 13 Jan 2015, 08:49 AM
Hello Emanuele,

Although that the SelectCommand of SqlDataSource control could be changed dynamically, it will not persist through postbacks, so you have to ensure that you are setting it on each postback. This is the standard behavior of the SqlDataSource and it is not related to RadGrid.

Having the above in mind, you should remove the condition if(!IsPostBack) or if the SelectCommand will be changed depending on some other conditions, you could store it is a Session variable and set it on each postback accordingly.

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Emanuele
Top achievements
Rank 1
Veteran
Answers by
Konstantin Dikov
Telerik team
Share this question
or