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

Check before Insert

4 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 07 Oct 2013, 06:40 PM
My rad grid is currently has full CRUD functionality.  It gives the end user the ablity to manage Encounters by Date.

They want me to add a check to see if an encounter has already been added for a date, if there has, promp the user with a message saying something like "There is already an encounter for this Date.. If you continue and additional encounter will be added."

Not really sure how to accomplish this in the RADGRID..I am tempted to pull the ADD portion of this form out and create a separate page for this.

Can this be done in the radgrid?  if so... any examples or help would be great.

Thanks

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Oct 2013, 06:31 AM
Hello,

Please try with the below code snippet.


-- Please add unique constrain in column 
ALTER TABLE ForumTable
ADD CONSTRAINT uc_Customdate UNIQUE (Customdate)

-- In item inserted event, handle error if user insert duplicate date.
protected void RadGrid1_ItemInserted(object sender, GridInsertedEventArgs e)
   {
       if (e.Exception != null)
       {
           e.ExceptionHandled = true;
           e.KeepInInsertMode = true;
           Label1.Text = "Error:- " + e.Exception.Message;
       }
       else
       {
           Label1.Text = string.Empty;
       }
   }


Let me know if any concern.

Thanks,
Jayesh Goyani
0
Ryan
Top achievements
Rank 1
answered on 09 Oct 2013, 11:08 AM
The user is allowed to add a second encounter on the same date, I just want to do a query and give them a notice before I actually do the insert letting the user know there is already an encounter on that date, and if they continue an additional encounter would be added.
0
Accepted
Konstantin Dikov
Telerik team
answered on 10 Oct 2013, 12:42 PM
Hi Ryan,

I have prepared a sample page with the requested functionality.

As you will notice, the used approach handles the "ItemCommand" server-side event, checks if a record with the same "CategoryName" exists in the database. If there is exactly one record with the same name, then a RadWindow with two RadButtons will be opened, and if the confirmation button is clicked, the record will be added. 

Please test it and see if it fulfills your requirement.

Hope that helps.

 

Regards,
Konstantin Dikov
Telerik
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 the blog feed now.
0
Ryan
Top achievements
Rank 1
answered on 10 Oct 2013, 02:33 PM
Perfect!  A few tweaks to this logic and got this working exactly the way I wanted.

Thanks again!
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Ryan
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or