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

[Solved] RadGrid Columns Validation

2 Answers 221 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcio Nascimento
Top achievements
Rank 1
Marcio Nascimento asked on 24 Sep 2009, 05:58 PM
Hi There,

I have a RadGrid with three NumericColumns.
When in EditMode, I need to check if the sum of the values of the three columns are not greater than 100%. If so, I might not let RadGrid update or insert.

I couldn't find any reference or example to accomplish that.

If someone could help...

Thanks.

Marcio Nascimento

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 25 Sep 2009, 07:56 AM
Hi Marcio,

Try the following code snippet and see whether it helps.

ASPX:
 
 . . . 
<telerik:GridNumericColumn UniqueName="NumericColumn1" DataField="Number"
</telerik:GridNumericColumn> 
<telerik:GridNumericColumn UniqueName="NumericColumn2" DataField="Number"
</telerik:GridNumericColumn> 
<telerik:GridNumericColumn UniqueName="NumericColumn3" DataField="Number"
</telerik:GridNumericColumn> 
 . . . 

C#:
 
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    GridEditableItem editItem = (GridEditableItem)e.Item; 
    RadNumericTextBox textBox1 = (RadNumericTextBox)editItem["NumericColumn1"].Controls[0]; 
    RadNumericTextBox textBox2 = (RadNumericTextBox)editItem["NumericColumn2"].Controls[0]; 
    RadNumericTextBox textBox3 = (RadNumericTextBox)editItem["NumericColumn3"].Controls[0]; 
 
    int total = Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text) + Convert.ToInt32(textBox3.Text); // Calculate the percentage here 
    if (total > 100) 
    { 
        e.Canceled = true// Cancel Update 
        Response.Write("Cancelled"); 
    } 
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
    GridEditableItem editItem = (GridEditableItem)e.Item; 
    RadNumericTextBox textBox1 = (RadNumericTextBox)editItem["NumericColumn1"].Controls[0]; 
    RadNumericTextBox textBox2 = (RadNumericTextBox)editItem["NumericColumn2"].Controls[0]; 
    RadNumericTextBox textBox3 = (RadNumericTextBox)editItem["NumericColumn3"].Controls[0]; 
 
    int total = Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text) + Convert.ToInt32(textBox3.Text); // Calculate the percentage here 
    if (total > 100) 
    { 
        e.Canceled = true// Cancell Insert 
        Response.Write("Cancelled"); 
    } 

Thanks,
Princy.
0
Marcio Nascimento
Top achievements
Rank 1
answered on 28 Sep 2009, 04:28 PM
Thanks Princy!
You help me a lot.

Best Regards,

Marcio Nascimento

Tags
Grid
Asked by
Marcio Nascimento
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Marcio Nascimento
Top achievements
Rank 1
Share this question
or