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

Add RequiredFieldValidator For combobox in Grid

4 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dominic
Top achievements
Rank 2
Dominic asked on 25 Sep 2008, 09:29 PM

Hi

I have a grid with a GridDropDownColomn and i tried to add a requiredFieldValidator to it, but it seems that i"m missing something.... First i use RadGrid1_ItemDataBound to add a "Please select item" in my RadComboBox, after that in the RadGrid1_ItemCreated, i'm looking for my radcombo and i associate the RequiredFieldValidator to it but it does'nt works. I assume that the requiredFieldValidator check for the selected text and not the value , so how i can make it works ? There is my code snippet :

Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound

If

TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then


    Dim Combo As RadComboBox = TryCast(e.Item.FindControl("RCB_ResponsibleID"), RadComboBox)

    Combo.Items.Insert(0,

New RadComboBoxItem(Resources.Resources.GRID_SELECT_RESPONSIBLE, Nothing)

End If

End Sub

Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated

If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then

Dim Combo As RadComboBox = TryCast(Item("ResponsibleID").FindControl("RCB_ResponsibleID"), RadComboBox)

Dim ResponsibleValidator As New RequiredFieldValidator

ResponsibleValidator.ControlToValidate = Combo.ID

ResponsibleValidator.InitialValue =

Nothing

ResponsibleValidator.SetFocusOnError = True

ResponsibleValidator.ErrorMessage = Resources.Resources.GRID_MUST_SELECT_RESPONSIBLE

Cell = Combo.Parent

Cell.Controls.Add(ResponsibleValidator)

End If

End Sub

Thanks in advance for your helps !

4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 29 Sep 2008, 09:18 AM
Hi Dominic,

Please review this help topic on how to add validators to RadGrid edit form.

Find more information about RadGrid event in the following articles:
http://www.telerik.com/help/aspnet-ajax/grdeventsequence.html
http://www.telerik.com/help/aspnet-ajax/grdcontrollifecycle.html

Let us know if this helps.

Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dominic
Top achievements
Rank 2
answered on 29 Sep 2008, 03:01 PM
Hi,

I dont have any problem to add a validator to a radtextbox control but it seems to work differently for the combobox because i cant make it works. I have fallowed the demo you gave me before asking for help... I'ave also tried to leave empty the first item of the combo, but nothing change the validator dont works with my combobox.

Thanks in advance for your help.
0
Accepted
Iana Tsolova
Telerik team
answered on 01 Oct 2008, 02:43 PM
Hi Dominic,

Please try setting the InvalidValue property of the validator as follows:

ResponsibleValidator.InitialValue = Resources.Resources.GRID_SELECT_RESPONSIBLE 

Find more about RadComboBox and validation here.

Let me know how it goes.

Best wishes,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dominic
Top achievements
Rank 2
answered on 01 Oct 2008, 03:36 PM

Hi

Thanks for your answer.

Everything is working great, thanks for your help.

Tags
Grid
Asked by
Dominic
Top achievements
Rank 2
Answers by
Iana Tsolova
Telerik team
Dominic
Top achievements
Rank 2
Share this question
or