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

Put validation in master detail table

1 Answer 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
illumination
Top achievements
Rank 2
illumination asked on 23 Nov 2010, 08:46 PM
Hello everyone!
I would like to know how to put validation in the master detail table comparing cost between the master total cost and the detail subtotal cost. Please see the attached image. and also when I add new record or update the existing record then it will also show this message if the master total cost is less than the detail subtotal cost too.

Please help.
Thank you!

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 26 Nov 2010, 12:37 PM
Hello illumination,

I believe you would need to retrieve the GridGroupHeaderItem from the detail table after the CRUD operation. All the text in the group header is rendered into a single cell accessible by the GridGroupHeaderItem.DataCell.Text property. You need to parse the Subtotal aggregate value from it. To retrieve the parent item's Total Cost value, you can put the field name into the master table's DataKeyNames collection. Then you can retrieve it using e.Item.OwnerTableView.ParentItem.GetDataKeyValue() method, where e.Item is your GridGroupHeaderItem instance. You can do all this in RadGrid's ItemDataBound event handler:

Copy Code
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridGroupHeaderItem)
    {
        GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item;
        double totalCost = (double)groupHeader.OwnerTableView.ParentItem.GetDataKeyValue("TotalCost");
        string groupHeaderText = groupHeader.DataCell.Text;
        double subtotal = 0d;
        //parse groupHeaderText and set subtotal
 
        if (subtotal > totalCost)
        {
            string errorMessage = "Valdation error message!";
            groupHeader.DataCell.Text = groupHeaderText + String.Format("<span style='color:red'>{0}</span>", errorMessage);
        }
    }
}

Hope this helps.

Veli
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
illumination
Top achievements
Rank 2
Answers by
Veli
Telerik team
Share this question
or