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

Radgrid update with unique constraint validation

3 Answers 263 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mrinalini
Top achievements
Rank 1
Mrinalini asked on 13 Sep 2012, 02:32 PM
Hi,
I have a radgrid with an edit form template. There are multiple entry fields in the edit form.
I have a textbox in a radgrid that must be unique. I have created a custom validator for the insert so that it checks to make sure the value does not exist in the database and this works fine. However, if I use the same custom validator in the radgrid edit template, it will not let me update a row with the original value because it sees that it is already in the database. I use  page.isvalid to check before updating the radgrid. How do I get around this issue? Any help is appreciated! Thanks!

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Sep 2012, 05:26 PM
Hello,

Also try with below code snippet.

<MasterTableView >
                 
                <Columns>
                  
                    <telerik:GridTemplateColumn UniqueName="FirstName">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                            <asp:Label ID="Label1" Visible="false" runat="server" Text="First name already exists"></asp:Label>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
                </Columns>
            </MasterTableView>
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            TextBox TextBox1 = item.FindControl("TextBox1") as TextBox;
             
             
            string strName = TextBox1.Text;
 
            // check if firstname is exists or not
 
            if (true) // if firstname is exists
            {
                Label Label1 = item.FindControl("Label1") as Label;
                Label1.Visible = true;
                e.Canceled = true;
            }
            else
            {
                // Perform Update Operation
            }
 
        }


Thanks,
Jayesh Goyani
0
Mrinalini
Top achievements
Rank 1
answered on 13 Sep 2012, 05:54 PM
Hi jayesh,

Thanks for your reply - it was very helpful.

I still have a problem with this though:

Checking if "first name" exists:
I have 2 other textboxes in the edit form for the radgrid (say last name and city). For an existing record, when user tries to update last name or city (or both), the record does not get updated because first name already exists.

How do I overcome this issue?

Thanks!
0
Radoslav
Telerik team
answered on 18 Sep 2012, 09:03 AM
Hi Mrinalini,

I am sending you a simple example which demonstrates the desired functionality. Please check it out and let me know if it helps you. Looking forward for your reply.

All the best,
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.
Tags
Grid
Asked by
Mrinalini
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Mrinalini
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or