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

RadGrid and SqlDataSource

3 Answers 499 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JMB
Top achievements
Rank 1
JMB asked on 07 Sep 2010, 09:26 AM
Hye,

I am using the RadGrid v2010.2.826.20 and I notice a strange behavior.
The RadGrid works when it is linked on a DataSource by its ID
But when I linked the RadGrid by the DataSource (the object reference ), the Column sorting doesn't work.
 

Common part
<asp:SqlDataSource runat="server" ID="SqlDataSource2"
    ConnectionString="<%$ ConnectionStrings:DEV_3.1ConnectionString %>"
    OldValuesParameterFormatString="original_{0}"
    SelectCommand="SELECT * FROM [M9999_Table]">
</asp:SqlDataSource>
 
<telerik:RadGrid ID="RadGrid2" runat="server" >
    <MasterTableView AllowSorting="true">
     </MasterTableView>
</telerik:RadGrid>

A) The code that works.
protected void Page_Load(object sender, EventArgs e)
{
    this.RadGrid2.DataSourceID = this.SqlDataSource2.ID;
}

B )The code that doesn't work.
protected void Page_Load(object sender, EventArgs e)
{
    this.RadGrid2.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid2_NeedDataSource);
}
 
void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    this.LoadData();
}
 
private void LoadData()
{
    this.RadGrid2.DataSource = this.SqlDataSource2;  
}




I attached handlers on the Selected and Selecting events od the SqlDataSource.
When I click on a column header in order to sort it.
By Method A : Two events are raised :
 - Selecting with a correct SortExpression.
 - Selected with a correct SortExpression.

By Method B : Four events are raised :
 - Selecting with a correct SortExpression.
 - Selected with a correct SortExpression.
and then
- Selecting with an empty SortExpression.
- Selected with an empty SortExpression.


I guest do something wrong, but I don't know what.

Any help will be appreciated.


3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 07 Sep 2010, 09:59 AM
Hi Pascal,

Could you please check if it makes any difference if you call the Select() method of the SqlDataSource control in the NeedDataSource event of the grid?
However I suggest that you avoid mixing the declarative and advanced data-binding for the grid, and in the NeedDataSource event to assign DataTable for instance, or another object already containing the desired data, to the grid DataSource directly.

Sincerely yours,
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
JMB
Top achievements
Rank 1
answered on 07 Sep 2010, 11:05 AM
Hi,

I changed  this code and column sorting works.
private void LoadData()
{
    //this.RadGrid2.DataSource = this.SqlDataSource2;
    RadGrid2.DataSource = this.SqlDataSource2.Select(new DataSourceSelectArguments()); ;
}
I have deal with a huge number of line and I doubt that this implementation will be very efficient because it doesn't take account of select argument (offset, maximum row number...)   


Bye the way, I need to sort on select and update, delete and insert rows.
And I must get and set rows from a SqlDataSource which is created by cs code, I cant declare it in aspx file.

In this case what will be the solution ?



0
Iana Tsolova
Telerik team
answered on 07 Sep 2010, 11:11 AM
Hello Pascal,

In this case I suggest that you implement custom paging for the grid as it is done in this online demo.

Greetings,
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
Tags
Grid
Asked by
JMB
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
JMB
Top achievements
Rank 1
Share this question
or