Add validation to droplist control

T

TJS

I have a control, called FieldBuilder, which generates a droplist
dynamically for a form.
I want to add validation to the droplist thru the 'OnItemCreated' function.

i can't seem to get the "controltoValidate" portion correct.
Can anyone help ???

-------error msg:---------------

BC30311: Value of type 'System.Web.UI.WebControls.DropDownList' cannot be
converted to 'String'.

---------code:------------------

'*******************************************************
Sub EventForm_ItemCreated(sender As Object, e As FieldBuilderEventArgs)
'*******************************************************
If e.ItemType = ItemType.FieldItem And e.ColumnName = "IDEvent" Then
Dim ctrlEvent As DropDownList = CType(e.Control, DropDownList)
ctrlEvent.Items.Insert(0, New ListItem("-- Select one --","-1"))
If vEventTeeTimeID > 0 then
Dim vID As String = Cstr(vEventTeeTimeID) 'Always string
ctrlEvent.SelectedIndex =
ctrlEvent.Items.IndexOf(ctrlEvent.Items.FindByValue(vID))
else
ctrlEvent.SelectedIndex =
ctrlEvent.Items.IndexOf(ctrlEvent.Items.FindByValue(""))
End if

'Add validation here
'-----------------------------
Dim compVal AS CompareValidator = New CompareValidator()
compVal.ErrorMessage = " Please, select something from the list"
compVal.ValueToCompare = "-1"
compVal.Type = ValidationDataType.String
compVal.Operator = ValidationCompareOperator.NotEqual
compVal.ControlToValidate = ctrlEvent '<== error is here
e.Item.Controls.Add(compVal)

End If
End sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top