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

Duplicate item validation

2 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ZAFFAR
Top achievements
Rank 1
ZAFFAR asked on 29 Feb 2012, 09:13 AM
I am trying to validate duplicate value in the Radgrid cell , but it validates same raw itself please help me find the solution.
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Duplicate product not allowed"
                            ControlToValidate="RadComboBox1" OnServerValidate="CustomValidator1_ServerValidate" >
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
            For Each dataItem As GridDataItem In RadGrid1.Items        
            If args.Value = CType(dataItem("pk_productid").FindControl("RadComboBox1"), RadComboBox).Text Then
                args.IsValid = False
            End If
 
        Next
       
    End Sub
 

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 05 Mar 2012, 08:12 AM
Hi,

I'm not completely sure what is the exact scenario you need to achieve and what is the issue you are currently facing. I would suggest you to review the following online resources which elaborates on this matter:
http://www.telerik.com/help/aspnet-ajax/grid-validation.html
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/validation/defaultcs.aspx


Kind regards,
Maria Ilieva
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.
0
ZAFFAR
Top achievements
Rank 1
answered on 05 Mar 2012, 08:36 AM
Its ok  I solved it with the following, thanks any ways . 
Protected Sub radgrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
        Dim combo As RadComboBox = TryCast(sender, RadComboBox)
        Dim item As GridDataItem = DirectCast(combo.NamingContainer, GridDataItem)
        Dim index As Integer = item.ItemIndex
        For Each row As GridDataItem In RadGrid1.Items
            If Not row.ItemIndex = item.ItemIndex Then
                If e.Text = CType(row("pk_productid").FindControl("RadComboBox1"), RadComboBox).Text Then
                    MsgBox("Duplicate product not allowed", MsgBoxStyle.Critical)
                    CType(item("pk_productid").FindControl("RadComboBox1"), RadComboBox).Text = "-"
                End If
            End If
        Next
    End Sub
Tags
Grid
Asked by
ZAFFAR
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
ZAFFAR
Top achievements
Rank 1
Share this question
or