Hi,
I'm trying to do footer validation where if the footer values in column a, b and c does not equal d, then update fails. Can you take a look at my code. Thanks.
I'm trying to do footer validation where if the footer values in column a, b and c does not equal d, then update fails. Can you take a look at my code. Thanks.
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
{
GridEditableItem editItem = (GridEditableItem)e.Item;
GridFooterItem footerItem = RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0] as GridFooterItem;
string column1 = footerItem["WEEKENDS_MTD"].Text;
string column2 = footerItem["HOLIDAYS_MTD"].Text;
string column3 = footerItem["BUSINESS_DAYS_MTD"].Text;
string total = footerItem["CALENDAR_DAYS_MTD"].Text;
int footervalue1;
int footervalue2;
int footervalue3;
int footervalue4;
int.TryParse(column1, out footervalue1);
int.TryParse(column2, out footervalue2);
int.TryParse(column3, out footervalue3);
int.TryParse(total, out footervalue4);
if (footervalue1 + footervalue2 + footervalue3 != footervalue4)
{
e.Canceled = true; // Cancel Update
Response.Write("Cancelled");
}
}
10 Answers, 1 is accepted
0

Elton
Top achievements
Rank 1
answered on 13 Sep 2012, 07:54 PM
bump
0

Garrett
Top achievements
Rank 1
answered on 13 Sep 2012, 08:01 PM
Hi Elton,
Can you post the markup for the Grid so I can try to reproduce it?
Also, what is the current behavior of the code? Does it always match, or throw an error?
Thanks,
Garrett
Can you post the markup for the Grid so I can try to reproduce it?
Also, what is the current behavior of the code? Does it always match, or throw an error?
Thanks,
Garrett
0

Elton
Top achievements
Rank 1
answered on 13 Sep 2012, 08:03 PM
The behavior is its cancelling every update even if the values do match. The intention is to only if they dont match.
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
AutoPostBack
=
"true"
DataSourceID
=
"SqlDataSource1"
GridLines
=
"None"
AllowAutomaticUpdates
=
"True"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
onupdatecommand
=
"RadGrid1_UpdateCommand"
PageSize
=
"12"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
Skin
=
"Windows7"
>
<
ExportSettings
ExportOnlyData
=
"True"
FileName
=
"BusinessDays"
>
</
ExportSettings
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataSourceID
=
"SqlDataSource1"
EditMode
=
"InPlace"
ShowFooter
=
"True"
ShowGroupFooter
=
"True"
DataKeyNames
=
"ROW_UNO"
>
<
CommandItemSettings
ShowExportToExcelButton
=
"true"
/>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ROW_UNO"
DataType
=
"System.Int32"
HeaderText
=
"ROW_UNO"
ReadOnly
=
"True"
SortExpression
=
"ROW_UNO"
UniqueName
=
"ROW_UNO"
Visible
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"YEAR"
DataType
=
"System.Int32"
HeaderText
=
"YEAR"
SortExpression
=
"YEAR"
UniqueName
=
"YEAR"
ReadOnly
=
"True"
ForceExtractValue
=
"Always"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
AllowFiltering
=
"False"
DataField
=
"PERIOD"
DataType
=
"System.Int32"
HeaderText
=
"PERIOD"
SortExpression
=
"PERIOD"
UniqueName
=
"PERIOD"
ReadOnly
=
"True"
ForceExtractValue
=
"Always"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
AllowFiltering
=
"False"
DataField
=
"OFFICE"
DataType
=
"System.Int32"
HeaderText
=
"OFFICE"
SortExpression
=
"OFFICE"
UniqueName
=
"OFFICE"
ReadOnly
=
"True"
ForceExtractValue
=
"Always"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"OFFICE_DESC"
HeaderText
=
"OFFICE DESCRIPTION"
SortExpression
=
"OFFICE_DESC"
UniqueName
=
"OFFICE_DESC"
ReadOnly
=
"True"
ForceExtractValue
=
"Always"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
AllowFiltering
=
"False"
DataField
=
"CALENDAR_DAYS_MTD"
DataType
=
"System.Int32"
HeaderText
=
"CALENDAR DAYS"
ReadOnly
=
"True"
SortExpression
=
"CALENDAR_DAYS_MTD"
UniqueName
=
"CALENDAR_DAYS_MTD"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0}"
ForceExtractValue
=
"Always"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
AllowFiltering
=
"False"
DataField
=
"WEEKENDS_MTD"
ReadOnly
=
"True"
DataType
=
"System.Int32"
HeaderText
=
"WEEKENDS"
SortExpression
=
"WEEKENDS_MTD"
UniqueName
=
"WEEKENDS_MTD"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0}"
ForceExtractValue
=
"Always"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
AllowFiltering
=
"False"
DataField
=
"HOLIDAYS_MTD"
DataType
=
"System.Int32"
HeaderText
=
"HOLIDAYS"
SortExpression
=
"HOLIDAYS_MTD"
UniqueName
=
"HOLIDAYS_MTD"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
AllowFiltering
=
"False"
DataField
=
"BUSINESS_DAYS_MTD"
DataType
=
"System.Int32"
HeaderText
=
"BUSINESS DAYS"
SortExpression
=
"BUSINESS_DAYS_MTD"
UniqueName
=
"BUSINESS_DAYS_MTD"
Aggregate
=
"Sum"
FooterAggregateFormatString
=
"{0}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
AllowFiltering
=
"False"
DataField
=
"SPREAD_OF_DAYS"
DataType
=
"System.Decimal"
HeaderText
=
"SPREAD OF DAYS"
SortExpression
=
"SPREAD_OF_DAYS"
UniqueName
=
"SPREAD_OF_DAYS"
>
</
telerik:GridBoundColumn
>
<
telerik:GridEditCommandColumn
>
</
telerik:GridEditCommandColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
UniqueName
=
"EditCommandColumn1"
>
</
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
</
telerik:RadGrid
>
0

Elton
Top achievements
Rank 1
answered on 14 Sep 2012, 03:08 PM
bump
0

Casey
Top achievements
Rank 1
answered on 14 Sep 2012, 05:29 PM
Hi Elton,
How many rows does your RadGrid have in it? Have you verified the values of footervalue1, footervalue2, footervalue3, and foortervalue4 are what you expect while debugging?
Thanks!
Casey
How many rows does your RadGrid have in it? Have you verified the values of footervalue1, footervalue2, footervalue3, and foortervalue4 are what you expect while debugging?
Thanks!
Casey
0

Elton
Top achievements
Rank 1
answered on 14 Sep 2012, 09:21 PM
12 rows
0

Casey
Top achievements
Rank 1
answered on 17 Sep 2012, 01:18 PM
Hi Elton,
Have you verified the values of footervalue1, footervalue2, footervalue3, and footervalue4 are what you expect while debugging?
Thanks,
Casey
Have you verified the values of footervalue1, footervalue2, footervalue3, and footervalue4 are what you expect while debugging?
Thanks,
Casey
0

Elton
Top achievements
Rank 1
answered on 17 Sep 2012, 02:44 PM
Yes, I've verified that they are the correct/incorrect values when performing the 'Update' procedure. The issue is the update is being cancelled (e.cancelled = true;) regardless of the values being correct/incorrect.
Any ideas?
Any ideas?
0
Hi Elton,
I am sending you a simple example which demonstrates how to achieve the desired functionality. Please check it out and let me know if it helps you. Looking forward for your reply.
Regards,
Radoslav
the Telerik team
I am sending you a simple example which demonstrates how to achieve the desired functionality. Please check it out and let me know if it helps you. Looking forward for your reply.
Regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Elton
Top achievements
Rank 1
answered on 20 Sep 2012, 03:15 PM
I figured it out, I tapped into the individual cell values and performed the validation there instead of trying to do it on the footer values total Thanks all for the help.