简体   繁体   English

如何将数据绑定到嵌套的DevExpress GridView控件?

[英]How do I Bind data to a nested DevExpress GridView control?

I'm new to DevExpress controls and am having issues with a master-detail gridview. 我是DevExpress控件的新手,但主从网格视图存在问题。

I'm using DXperience-11.2. 我正在使用DXperience-11.2。

I can easily bind an object to the parent GridView by doing the following: 通过执行以下操作,我可以轻松地将对象绑定到父GridView:

var myObject = myObject.Retrieve(id);

parentGridView.DataSource = myObject;
parentGridView.DataBind();

I'm having difficulty binding to the nested child GridView. 我有困难结合到嵌套子GridView控件。 I'm using the following code (as I've used many times before with nested asp:Repeaters) but the resulting var childGrid object is always null. 我正在使用以下代码(就像我之前多次使用嵌套的asp:Repeaters一样),但是生成的var childGrid对象始终为null。

var childGrid = (ASPxGridView)parentGridView.FindControl("childGridView");

var myObject2 = myObject2.Retrieve(id);

childGrid.DataSource = myObject2;
childGrid .DataBind();

Any help would be greatly appreciated. 任何帮助将不胜感激。

Regards Kris 问候克里斯

Ok Thanks for the suggestions posted but I managed to come up with the solution. 好,谢谢您发布的建议,但我设法提出了解决方案。

I added the following event to the parent gridview... 我将以下事件添加到父gridview中...

OnBeforePerformDataSelect="detailGrid_DataSelect"

This event fires when you click on a row in the parent gridview. 当您单击父网格视图中的一行时,将触发此事件。 The parent gridview row expands and the event fires. 父网格视图行将展开,事件将触发。

Then in my code behind I did the following code... 然后在后面的代码中,我做了以下代码...

    protected void detailGrid_DataSelect(object sender, EventArgs e)
    {
        var myObject2 = myObject2.Retrieve(id);

        ASPxGridView grid = (sender as ASPxGridView);
        grid.DataSource = myObject2;
    }

To begin I retrieved the object I wanted to bind to the nested/child GridView. 首先,我检索了要绑定到嵌套/子GridView的对象。 Then cast the object sender to an ASPxGridView Object and bind the data object I retrieved. 然后将对象发送方强制转换为ASPxGridView对象,并绑定我检索到的数据对象。

I was going wrong because I trying to find the nested GridView control using the .FindControl method in this event when really the object sender is the nested GridView object. 我做错了,因为在此事件中,当对象发送者确实是嵌套的GridView对象时,我尝试使用.FindControl方法查找嵌套的GridView控件。

Hope this helps anyone who was in the same pickle as me! 希望这对和我一起泡菜的人有所帮助!

Kris 克里斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM