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

Server side validation from RadGrid

4 Answers 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy Green
Top achievements
Rank 1
Andy Green asked on 15 Mar 2010, 04:23 PM
Hi Team

I have a RadGrid with a Edit Form Setting of Template and a load of textboxes. Some of these have Requiredfield validator on them and this all works fine.

What I also need to do is a server side lookup on a value and not submit the data if that value exists. So I fill out my form, hit insert (its a new record) and if I single step the code it detects the duplicate value, but how do I then return to the radgrid, in insert mode, and show the error (I have a label control set to visible = false and want to show it.)

What is happening is the radgrid closes the form and I looses my data, and the label is never seen.

Andy

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Mar 2010, 07:59 AM
Hi,

Try setting the e.Canceled to true to cancel the closing of the Insert form on duplicate entry .

  protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
    { 
      if("Duplicate exists"
        { 
         e.Canceled = true
        } 
          
    } 

Princy
0
Andy Green
Top achievements
Rank 1
answered on 16 Mar 2010, 09:03 AM
Thanks Princy

Andy
0
Andy Green
Top achievements
Rank 1
answered on 16 Mar 2010, 09:26 AM
How would I disable some of he text box control on edit, but have them available for insert.

I have the follwoing code but it disables the control all the time, I cant differentiate between edit and insert.
    Private Sub rgLocations_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgLocations.ItemCreated  
 
        'disable the Location Code for edits as its the PK  
        If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then  
            Dim UpdatedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
            Dim LocationCodeAs TextBox = CType(UpdatedItem.FindControl("txtLocationCode"), TextBox)  
            LocationCode.Enabled = False 
        End If  
 
    End Sub 

Andy
0
Accepted
Princy
Top achievements
Rank 2
answered on 17 Mar 2010, 05:45 AM
Hi,

Please  have a look at the link below which discusses on the same:
Distinguish edit/insert mode on ItemCreated/ItemDataBound

Princy
Tags
Grid
Asked by
Andy Green
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Andy Green
Top achievements
Rank 1
Share this question
or