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

[Solved] RadGrid sorting and interfaces

6 Answers 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 24 Apr 2008, 08:49 AM
Hello telerik support team,

I have a problem with sorting if I bind an "interface list" to the radgrid. E.g. I have the following code:
AppUser.cs:
class AppUser : IAppUser
{
public string Account { get; set; }
    public string Password { get; set; }
}

Person.cs
class Person: IPerson
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

IAppUser.cs
public interface IAppUser : IPerson
{
string Account { get; set; }
string Password { get; set; }
}

IPerson.cs
public interface IPerson
{
    string FirstName { get; set; }
    string LastName { get; set; }
}

grid.aspx:
<asp:ScriptManager ID="scriptManager" runat="server"></asp:ScriptManager>
<telerik:RadGrid ID="dgAppuser" runat="server" AutoGenerateColumns="false" AllowSorting="true">
<MasterTableView AllowNaturalSort="false">
<Columns>
<telerik:GridBoundColumn HeaderText="Account" DataField="Account"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Password" DataField="Password"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="First Name" DataField="FirstName"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Last Name" DataField="LastName"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>

grid.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
dgAppuser.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(dgAppuser_NeedDataSource);
}
void dgAppuser_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
dgAppuser.DataSource = AppUser.GetAll();
}
The AppUser.GetAll() method returns an IList<IAppUser> object.
When I bind the list to the grid, the binding works, but if I try to sort by the property FirstName or LastName I get the following error:
IndexOutOfRangeException: Column LastName was not found.

If the GetAll() method returns IList<AppUser> instead of IList<IAppUser> the sorting is works.

Is there a solution for this problem or must I add all properties from the base interface also to the derived interface?

Thanks in advance.

Thomas Mayer

6 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 29 Apr 2008, 08:42 AM
Hello Markus,

Most probably the reason for this is related to the fact that some of the properties inherited from an interface are not "visible" for the grid. Can you try the same with standard MS GridView to see what will be the result?

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Markus
Top achievements
Rank 2
answered on 12 Jun 2008, 06:53 AM
Did someone find a solution? I encounter a similar problem
0
Markus
Top achievements
Rank 2
answered on 12 Jun 2008, 07:07 AM
Alright: I figured out the following thing:

I have an Interface that looks like :
public interface IA : IB
{
    string AdditionalInfo { get; set; }
}


I have the implementation:

public class A
{
    #region IB members
    public string Id { get { } set { } }
    #endregion

    #region IA members
    public string AdditionalInfo { get { } get { } }
    #endregion
}



Now you cannot sort for members that are defined in the interface IB.
But you can access them in the radgrid. This behaviour is indeed very disturbing. Either you should not be able to access any of the members of IB or you should be able to do all other things beside showing them too. (like sorting etc.)

Pls tell me how you plan to handle this issue in your future builds. Actually I don't want to change my domain model.
And I'm not able to know about Implementations of Interfaces in my frontend.
And I'm not willing to do some sort of wrapping ;-)

Thx in advance and kind regards

0
Rosen
Telerik team
answered on 16 Jun 2008, 08:46 AM
Hi Markus,

A possible way to workaround this behavior is to implement ITypedList in order to expose the base interface's properties. Or you may consider using instead an abstract class which implements the necessary interfaces.

Kind regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Markus
Top achievements
Rank 2
answered on 16 Jun 2008, 08:57 AM
Hi Rosen!

As I already said:

"And I'm not able to know about Implementations of Interfaces in my frontend.
And I'm not willing to do some sort of wrapping ;-)"

I don't think that making a wrapper in this case is good practice, as I would only propagate the accumulated members of the two interfaces. I agree with you that this solution would be a clean solution but it would be a "bad smell" :-)

Don't you think it is the right behaviour to be able to sort for every column that can be displayed?

How can we achieve a solution? Is it rather a bug report than a feature request?

Thx in advance & kind regards

0
Rosen
Telerik team
answered on 18 Jun 2008, 04:27 PM
Hello Markus,

We will be more than happy to add this functionality but unfortunately there is no way for finding at runtime if the interface inherits from another interface.

Kind regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Markus
Top achievements
Rank 2
Rosen
Telerik team
Share this question
or