DevExpress Grid Show Data from One to Many

Kasus: project memiliki relasi one-to-many terhadap history_afe. Pada tabel ingin ditampilkan data status yang merupakan status project terakhir dari tabel history_afe.

Capture

ASPX
[code language=”aspx”]
<dx:GridViewDataTextColumn FieldName="Status" VisibleIndex="30" Caption="Status">
<Settings AllowAutoFilter="False" AllowSort="False" />
<DataItemTemplate>
<dx:ASPxLabel ID="LastStatus" runat="server" OnInit="LastStatus_Init"></dx:ASPxLabel>
</DataItemTemplate>
</dx:GridViewDataTextColumn>

[/code]

C#
[code language=”csharp”]
protected void LastStatus_Init(object sender, EventArgs e)
{
DevExpress.Web.ASPxEditors.ASPxLabel label = (DevExpress.Web.ASPxEditors.ASPxLabel)sender;

GridViewDataItemTemplateContainer c = label.NamingContainer as GridViewDataItemTemplateContainer;
string idProgram = (string)c.KeyValue;
history_afe lastHistory = context.history_afe.Where(m => m.id_program == idProgram).OrderByDescending(m => m.date).FirstOrDefault();
if (lastHistory != null)
label.Text = lastHistory.status;
}

[/code]

Chandra Oemaryadi has written 244 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>