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

Databinding failed, property not found?

3 Answers 526 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Diego
Top achievements
Rank 1
Diego asked on 22 Oct 2020, 07:42 PM

Hi. I'm new to the RadGrid, and I'm having an error when trying to databind it to a collection of objects coming from an externally provided component.

When I try to databind it, I get a message saying "[TypeName] does not contain a property with the name [PropertyName]".

While the object does have a member with the specified name, I couldn't be sure whether said member is a property or a regular field.

Does this make a difference for RadGrid?

If so, is there any workaround besides having to pester my component's provider to change the way their data objects are defined?

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 26 Oct 2020, 03:52 PM

Hi Diego,

Could you please ensure if the values set to the DataKeyNames or/and ClientDataKeyNames properties of the RadGrid MasterTableView (or of any hierarchically nested GridTableViews) are existing accessible(public) properties of the Object class?

Here is a basic sample:

Declaration:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Width="800px" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID" >
        <Columns>
            <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32"
                FilterControlAltText="Filter OrderID column" HeaderText="OrderID"
                ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipName"
                FilterControlAltText="Filter ShipName column" HeaderText="ShipName"
                SortExpression="ShipName" UniqueName="ShipName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCountry"
                FilterControlAltText="Filter ShipCountry column" HeaderText="ShipCountry"
                SortExpression="ShipCountry" UniqueName="ShipCountry">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C# code:

protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    (sender as RadGrid).DataSource = GetOrders();
}

private List<Order> GetOrders()
{
    List<Order> orders = new List<Order>();
    for (int i = 0; i < 10; i++)
    {
        var index = i + 1;
        var order = new Order()
        {
            OrderId = index,
            ShipName = "ShipName " + index,
            ShipCountry = "Country " + index
        };
        orders.Add(order);
    }
    return orders;
}

public class Order
{
    public int OrderId { get; set; }
    public string ShipName { get; set; }
    public string ShipCountry { get; set; }
}
You may find it useful to check out the following resources:

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Diego
Top achievements
Rank 1
answered on 26 Oct 2020, 04:50 PM

Well, I probably didn't make the question clear enough.

The thing is, your hypothetical Order object would be defined as 

 

public class Order {
    public int OrderId;
    public string ShipName;
    public string ShipCountry;
}
0
Doncho
Telerik team
answered on 29 Oct 2020, 09:44 AM

Hi Diego,

Thank you for the clarification!

I am afraid that in general, data binding to objects in the .Net framework itself, is only allowed with properties but not with fields, Databinding Web Forms to Objects as opposed to Datasets

Therefore, some additional implementation would be needed in advance, to prepare the data in a bindable format. Find more information about Binding RadGrid in the Telerik RadGrid Data Binding section in our documentation.

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Diego
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Diego
Top achievements
Rank 1
Share this question
or