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.FindByValu e(vID))
else
ctrlEvent.SelectedIndex =
ctrlEvent.Items.IndexOf(ctrlEvent.Items.FindByValu e(""))
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