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

Validation control in RadGrid

2 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sam
Top achievements
Rank 1
sam asked on 14 Jul 2010, 01:38 PM
Hello ,
I have a radgrid and sqldatasource
in the database i have a unique key constraint to check if username  exist

When i am trying to add new record from radgrid  of  an existing username    i get this error

Violation of UNIQUE KEY constraint 'IX_Users'. Cannot insert duplicate key in object 'dbo.Users'.
The statement has been terminated


that s because i am using a unique key constraint

how can i handle this error to display in a Validation summary for example or a label
to ask user or tell him that username exist already and must insert another valid username

I tried to use  validationsettings property of rad grid but i failed please help
thanks for anyone who can solve my problem

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Jul 2010, 01:49 PM
Hello Sam,

It is possible to catch the exception (if any) in ItemInserted event if you are using AutoMatic operations as illustrated in demo.

CS:
protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
{
    if (e.Exception != null)
    {
        e.ExceptionHandled = true;
        // SetMessage("Product cannot be inserted. Reason: " + e.Exception.Message);   // Set the label text
    }
    else
    {
        SetMessage("New product is inserted!");
    }
}


Thanks,
Princy.
0
sam
Top achievements
Rank 1
answered on 14 Jul 2010, 02:15 PM
Thank you Princy Philip  for your quick response ...you solved my problem !
I announce you a "Hero"
Tags
Grid
Asked by
sam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
sam
Top achievements
Rank 1
Share this question
or