Hi, this is my second post about this since my first was not answered and then I guess removed.
I am using MS Visual Studio Professional. The code is ASP.net. I am using Telerik's RadGrid (latest versions I assume, I don't know how to tell..)
I am trying to add a Required validation to a bound Drop Down Box in the RadGrid. I am thinking my problem is a syntax issue because I can get it to work for a regular text box, but the dropdown box just does not work.
This is the code I use for the textbox which works (trying to use the code block format):
But when I add the same code for a drop down box, it does not work:
I am using MS Visual Studio Professional. The code is ASP.net. I am using Telerik's RadGrid (latest versions I assume, I don't know how to tell..)
I am trying to add a Required validation to a bound Drop Down Box in the RadGrid. I am thinking my problem is a syntax issue because I can get it to work for a regular text box, but the dropdown box just does not work.
This is the code I use for the textbox which works (trying to use the code block format):
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem) Dim editor As GridTextBoxColumnEditor = DirectCast(item.EditManager.GetColumnEditor("CurrencyTarget_NativeCurrent"), GridTextBoxColumnEditor) Dim cell As TableCell = DirectCast(editor.TextBoxControl.Parent, TableCell) Dim validator As New CompareValidator ' RequiredFieldValidator() editor.TextBoxControl.ID = "NCReqValidator" validator.ControlToValidate = editor.TextBoxControl.ID validator.Operator = ValidationCompareOperator.GreaterThanEqual validator.ValueToCompare = "0" validator.ErrorMessage = "* Native Current is a required field" cell.Controls.Add(validator) End IfEnd SubBut when I add the same code for a drop down box, it does not work:
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then Dim item2 As GridEditableItem = TryCast(e.Item, GridEditableItem) Dim editor2 As GridDropDownListColumnEditor = DirectCast(item2.EditManager.GetColumnEditor("ddCountryCode"), GridDropDownListColumnEditor) Dim cell2 As TableCell = DirectCast(editor2.DropDownListControl.Parent, TableCell) Dim validator2 As New CompareValidator ' RequiredFieldValidator() editor2.DropDownListControl.ID = "CCReqValidator" validator2.ControlToValidate = editor2.DropDownListControl.ID validator2.Operator = ValidationCompareOperator.NotEqual validator2.ValueToCompare = "XXX" validator2.ErrorMessage = "* Country Code is a required field" cell2.Controls.Add(validator2) End IfEnd Sub