Hi,
I have GridDropDownColumn with EnableEmptyListItem = "true" EmptyListItemValue="0" EmptyListItemText="Select" in my RadGrid and required field validator as well and i am experiencing a problem that my validator is not fired when the drop down selected text is "Select". I have many fields as well in an order (ie) For Ex. User Name, Password, User Type and Contact No etc., in this User Type is the drop down list. The required field validator is fired for username, password,contact no and for user type its not firing. So i used to check the separately OnInsertCommand.
But I required is the required field validator should fire that. So i need some help in this regards
Thanks,
Kannan
I have GridDropDownColumn with EnableEmptyListItem = "true" EmptyListItemValue="0" EmptyListItemText="Select" in my RadGrid and required field validator as well and i am experiencing a problem that my validator is not fired when the drop down selected text is "Select". I have many fields as well in an order (ie) For Ex. User Name, Password, User Type and Contact No etc., in this User Type is the drop down list. The required field validator is fired for username, password,contact no and for user type its not firing. So i used to check the separately OnInsertCommand.
But I required is the required field validator should fire that. So i need some help in this regards
Thanks,
Kannan
5 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 24 Jan 2011, 08:27 AM
Hello Kannan,
This is the code that I tried in my application. Please check this and find whether you have missed anything.
ASPX:
C#:
Thanks,
Princy.
This is the code that I tried in my application. Please check this and find whether you have missed anything.
ASPX:
<
telerik:GridDropDownColumn
ListTextField
=
"UserType"
ListValueField
=
"UserType"
DataField
=
"UserType"
DropDownControlType
=
"DropDownList"
UniqueName
=
"GridDropDownColumn2"
DataSourceID
=
"SqlDataSource1"
EnableEmptyListItem
=
"true"
EmptyListItemValue
=
"0"
EmptyListItemText
=
"Select"
>
</
telerik:GridDropDownColumn
>
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
{
GridEditFormInsertItem insertItem = e.Item
as
GridEditFormInsertItem;
DropDownList dropDownList1 = insertItem[
"GridDropDownColumn2"
].Controls[0]
as
DropDownList;
GridDropDownColumnEditor editor = (GridDropDownColumnEditor)insertItem.EditManager.GetColumnEditor(
"GridDropDownColumn2"
);
TableCell cell = (TableCell)editor.ContainerControl;
RequiredFieldValidator validator =
new
RequiredFieldValidator();
validator.ControlToValidate = dropDownList1.ID;
validator.InitialValue =
"0"
;
validator.ErrorMessage =
"*"
;
cell.Controls.Add(validator);
}
}
Thanks,
Princy.
0

Kannan
Top achievements
Rank 1
answered on 24 Jan 2011, 10:47 AM
Hi Princy,
Thanks for your code and I have missed out
Thanks for your code and I have missed out
validator.InitialValue =
"0"
;
Now its working fine.
Thanks & Regards
Kannan.S
0

Carl
Top achievements
Rank 1
answered on 05 Dec 2014, 09:27 PM
I'm working on a similar project using RadGrid with GridDropDownColumns and EnableEmptyListItem options. I'm trying to implement a solution like the one proposed by Princy but I was wondering if I could accomplish the same thing with a RadComboBox instead of the ASP.NET DropDownList control? I tried to change:
DropDownList dropDownList1 = insertItem["GridDropDownColumn2"].Controls[0] as DropDownList;
to
RadComboBox dropDownList1 = insertItem["GridDropDownColumn2"].Controls[0] as RadComboBox;
However, now the validator will not fire, but it works correctly if I use DropDownList instead of RadCombBox.
Please advise if this is a supported scenario or if I must use DropDownList instead.
Thanks.
DropDownList dropDownList1 = insertItem["GridDropDownColumn2"].Controls[0] as DropDownList;
to
RadComboBox dropDownList1 = insertItem["GridDropDownColumn2"].Controls[0] as RadComboBox;
However, now the validator will not fire, but it works correctly if I use DropDownList instead of RadCombBox.
Please advise if this is a supported scenario or if I must use DropDownList instead.
Thanks.
0
Hi Carl,
The only difference when RadComboBox control is used is that the InitialValue of the validator must be set to "Select" instead of "0":
Additionally, I would like to point out that you can accomplish the same behavior from the markup only:
Hope this helps.
Regards,
Konstantin Dikov
Telerik
The only difference when RadComboBox control is used is that the InitialValue of the validator must be set to "Select" instead of "0":
validator.InitialValue =
"Select"
;
Additionally, I would like to point out that you can accomplish the same behavior from the markup only:
<
telerik:GridDropDownColumn
ListTextField
=
"CompanyName"
ListValueField
=
"CompanyName"
DataField
=
"CompanyName"
DropDownControlType
=
"RadComboBox"
UniqueName
=
"GridDropDownColumn2"
DataSourceID
=
"SqlDataSource1"
EnableEmptyListItem
=
"true"
EmptyListItemValue
=
"0"
EmptyListItemText
=
"Select"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"true"
>
<
RequiredFieldValidator
ValidateRequestMode
=
"Enabled"
InitialValue
=
"Select"
ErrorMessage
=
"*"
></
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridDropDownColumn
>
Hope this helps.
Regards,
Konstantin Dikov
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0

Carl
Top achievements
Rank 1
answered on 10 Dec 2014, 05:38 PM
Excellent! I was able to swap to using RadComboBox for my grid editors successfully, thanks for the help.