
Rizwan Ansari
Top achievements
Rank 1
Rizwan Ansari
asked on 29 Nov 2010, 12:36 PM
Hello Sir,
How can i make validation for GridCheckBoxColumn.
I have a dropdownlist depending upon the value the checkbox is visible/hide.
but i want when checkbox is visible it should validate..if checkbox is disabled then no need for validation..
Please Help.
Thanks
How can i make validation for GridCheckBoxColumn.
I have a dropdownlist depending upon the value the checkbox is visible/hide.
but i want when checkbox is visible it should validate..if checkbox is disabled then no need for validation..
Please Help.
Thanks
5 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 29 Nov 2010, 01:22 PM
Hello,
I guess you want to hide/show the DropDownList based on checkbox status and from client side.
If so one suggestion is:
In the ItemCreated event, access the CheckBox control and DropDownList control and get the ClientIDs.
Now attach "onclick" event from to checkbox and pass the client objects of checkbox and DropDownList ClientID.
In the client side event handler, access the DrodDownList from the ClientID passed, and set the property as required.
Hope this suggestion helps.
-Shinu.
I guess you want to hide/show the DropDownList based on checkbox status and from client side.
If so one suggestion is:
In the ItemCreated event, access the CheckBox control and DropDownList control and get the ClientIDs.
Now attach "onclick" event from to checkbox and pass the client objects of checkbox and DropDownList ClientID.
In the client side event handler, access the DrodDownList from the ClientID passed, and set the property as required.
Hope this suggestion helps.
-Shinu.
0

Rizwan Ansari
Top achievements
Rank 1
answered on 29 Nov 2010, 02:09 PM
Hi Shinu.
Thanks for reply.
i am able to show/hide checkbox according to dropdown value.
suppose i select value and check box is visible then i want validation from client..means checkbox should be checked before insert.
if checkbox is not visible then i dont want validation should be done.
i hope understand.
Thanks
Thanks for reply.
i am able to show/hide checkbox according to dropdown value.
suppose i select value and check box is visible then i want validation from client..means checkbox should be checked before insert.
if checkbox is not visible then i dont want validation should be done.
i hope understand.
Thanks
0

Princy
Top achievements
Rank 2
answered on 30 Nov 2010, 08:28 AM
Hello Rizwan,
In order to achieve your requirement, store the GridCheckBoxColumn ID in a HiddenField when it is insert mode. Then in grid 'OnCommand' client event access the CheckBox using the HiddenField value and perform validation. Sample code is given below for your reference.
ASPX:
C#:
ASPX:
Java Script:
Thanks,
Princy.
In order to achieve your requirement, store the GridCheckBoxColumn ID in a HiddenField when it is insert mode. Then in grid 'OnCommand' client event access the CheckBox using the HiddenField value and perform validation. Sample code is given below for your reference.
ASPX:
<
asp:HiddenField
ID
=
"HiddenField1"
runat
=
"server"
/>
C#:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
{
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
CheckBox chkbox = (CheckBox)insertItem[
"GridCheckBoxColumn"
].Controls[0];
HiddenField1.Value = chkbox.ClientID;
}
}
ASPX:
<
ClientSettings
>
<
ClientEvents
OnCommand
=
"OnCommand"
></
ClientEvents
>
</
ClientSettings
>
Java Script:
function
OnCommand(sender, args) {
args.get_commandName() ==
"PerformInsert"
{
var
checkbox = $get(document.getElementById(
'HiddenField1'
).value);
if
(checkbox !=
null
) {
// checkbox will be null if it is not visible
if
(!checkbox.checked) {
alert(
"checkbox should be checked before insert"
);
args.set_cancel(
true
);
}
}
}
}
Thanks,
Princy.
0

Rizwan Ansari
Top achievements
Rank 1
answered on 30 Nov 2010, 09:13 AM
Hi shinu.
Thnaks for reply..but unfortunately when i click add new/edit record..throws an error "object required"..i am showing you the code.please take a look and guide me.i thik error in javascript on line
Thnaks for reply..but unfortunately when i click add new/edit record..throws an error "object required"..i am showing you the code.please take a look and guide me.i thik error in javascript on line
var
checkbox = $get(document.getElementById('HiddenField1').value);
if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
{
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
CheckBox chkbox1 = (CheckBox)insertItem["approved"].Controls[0];
HiddenField1.Value = chkbox1.ClientID;
chkbox1.ID = "CheckValidate";
RequiredFieldValidator reqValidator2 = new RequiredFieldValidator();
reqValidator2.ID = "RequiredFieldValidator2";
reqValidator2.ErrorMessage = "Approved Required";
reqValidator2.ControlToValidate = "CheckValidate";
insertItem["approved"].Controls.Add(reqValidator2);
TextBox txtbx = (TextBox)insertItem["Amount"].Controls[0];
txtbx.ID = "TextValidate";
RequiredFieldValidator reqValidator = new RequiredFieldValidator();
reqValidator.ID = "RequiredFieldValidator1";
reqValidator.ErrorMessage = "Amount Required";
reqValidator.ControlToValidate = "TextValidate";
insertItem["Amount"].Controls.Add(reqValidator);
}
0

Princy
Top achievements
Rank 2
answered on 01 Dec 2010, 12:40 PM
Hello Rizwan,
Check whether you have added a HiddenField with ID 'HiddenField1' in your page. And try the following way to access the CheckBox.
var checkbox = document.getElementById(document.getElementById('HiddenField1').value);
Then in code behind try the following approach instead of giving an explicit ID to CheckBox.
C#:
Thanks,
Princy.
Check whether you have added a HiddenField with ID 'HiddenField1' in your page. And try the following way to access the CheckBox.
var checkbox = document.getElementById(document.getElementById('HiddenField1').value);
Then in code behind try the following approach instead of giving an explicit ID to CheckBox.
C#:
if
(e.Item
is
GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
{
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
CheckBox chkbox1 = (CheckBox)insertItem[
"approved"
].Controls[0];
HiddenField1.Value = chkbox1.ClientID;
RequiredFieldValidator reqValidator2 =
new
RequiredFieldValidator();
reqValidator2.ID =
"RequiredFieldValidator2"
;
reqValidator2.ErrorMessage =
"Approved Required"
;
reqValidator2.ControlToValidate = chkbox.ID;
. . . . . . .
}
Thanks,
Princy.