473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Add validation to droplist control

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.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
Nov 19 '05 #1
2 1141
TJS, the ControlToValidate property is the ID of the control (string),
not the control itself. So, it would be:

compVal.ControlToValidate = ctrlEvent.ID

Jason Bentley
http://geekswithblogs.net/jbentley

Nov 19 '05 #2
TJS
thank you!

"Jason Bentley" <im****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
TJS, the ControlToValidate property is the ID of the control (string),
not the control itself. So, it would be:

compVal.ControlToValidate = ctrlEvent.ID

Jason Bentley
http://geekswithblogs.net/jbentley

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stanley J Mroczek | last post by:
I am trying to load a droplist in VB when the edit is clicked in a datagrid. I tried to use OnDataBinding and loading the droplist in subroutine "loaddd". I get this error Object reference not set...
4
by: Tim Meagher | last post by:
I am trying to use both validation controls and to add submit button attributes, but when I add the button attributes, the javascript fpr the validation controls is no longer created for the page. ...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
2
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post...
4
by: TJS | last post by:
After a post back the selected index should be rest in a droplist to match user's choice, but page always show selected item as first one in the droplist. How can iforce the selected item to be...
2
by: TJS | last post by:
need help with trying to set selected value on a droplist. -- tried vCaptainID as integer and string , no luck -- tried it in pre render and also after droplist is created , no luck =========...
5
by: TJS | last post by:
I need to add validation to drodownlist control but it sends back an error message that says: "System.Web.UI.WebControls.DropDownList' does not allow child controls" the code is : If...
2
by: Tim Frawley | last post by:
Source code attached indicates my problem with validation and a button bar save button. Fill the Textbox with some text then tab off the control. The message box will display the text in the...
0
by: yuchang | last post by:
Hi, I try to use a droplist control to show a list value from Database table "A", and the droplist control is an item of a formview control, its data from Database table "B". My problem is how...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.