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

RadGrid to not insert a duplicate record

4 Answers 347 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Terje Sondresen
Top achievements
Rank 1
Terje Sondresen asked on 08 Sep 2011, 11:43 AM
Basically need a way to check that the newly inserted record does not already exist in the rad grid.

my insert command code looks like below. and it works fine for checking that not a blank record is inserted, I just need to add a check that a name does not already exist. Any help would be appreciated.

Protected

Sub cEventTypesGrid_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles cEventTypesGrid.InsertCommand

 

 

Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)

 

Dim vLogin As TableCell = editedItem("Name")

Dim vTxtLogin As String = (CType(vLogin.Controls(0), RadComboBox)).SelectedValue


If
vTxtLogin = "" Then

 

Throw New Exception("Name cannot be blank."

End If

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Sep 2011, 06:11 PM
Hello,

protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
       {
           GridEditableItem item = (GridEditableItem)e.Item;
           TableCell vLogin = item["Name"];
           string vTxtLogin = (vLogin.Controls[0] as RadComboBox).SelectedValue;
 
           bool IsvTxtLoginIsAvialable = true; // do your logic here and set flag here
           if (IsvTxtLoginIsAvialable)
           {
               // Insert functionality should come here
           }
           else
           {
               //Label errorMessage = new Label(); // take one label for show the error message
               errorMessage.Text = "this user is alraedy available.";
               e.Canceled = true;
           }
 
       }

let me know if any concern.

Thanks,
Jayesh Goyani
0
Terje Sondresen
Top achievements
Rank 1
answered on 09 Sep 2011, 06:44 AM
Hi thanks,

But Im not sure I understood  the answer,

Im basically looking for the logic to compare that the newly enterered name does not match one already in the list
0
Radoslav
Telerik team
answered on 13 Sep 2011, 09:08 AM
Hello Terje,

You could try querying the database into the InsertCommand and check if the value into the vTxtLogin variable already exists into some record. If it exists you could cancel the InsertCommand. Please give it try and let me know if you experience any problems.

Greetings,
Radoslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Sep 2011, 11:07 AM
Hello,

List<GridDataItem> Items = (from item in RadGrid1.MasterTableView.Items.Cast<GridDataItem>()
                                    where item["Name"].Text!= "Your New Name"
                                    //&& ((CheckBox)item.FindControl("chkSelect")).Checked
                                    select item).ToList();

if you get Items.count > 0 then name exists.

let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Terje Sondresen
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Terje Sondresen
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or