8 Answers, 1 is accepted
0
Jayesh Goyani
Top achievements
Rank 2
answered on 03 Sep 2011, 06:03 AM
Hello COREY,
Grid / Flexible Server-Side Validation
or
Let me know if any concern.
Thanks,
Jayesh Goyani
Grid / Flexible Server-Side Validation
or
<
rad:RadGrid
id
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"False"
>
<
MasterTableView
>
<
Columns
>
<
rad:GridBoundColumn
UniqueName
=
"ContactName"
HeaderText
=
"ContactName"
DataField
=
"ContactName"
></
rad:GridBoundColumn
>
<
rad:GridEditCommandColumn
UniqueName
=
"EditCommandColumn"
></
rad:GridEditCommandColumn
>
</
Columns
>
</
MasterTableView
>
</
rad:RadGrid
>
private
void
RadGrid1_ItemCreated(
object
sender, Telerik.WebControls.GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = e.Item
as
GridEditableItem;
GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor(
"ContactName"
);
TableCell cell = (TableCell)editor.TextBoxControl.Parent;
RequiredFieldValidator validator =
new
RequiredFieldValidator();
editor.TextBoxControl.ID =
"ID_for_validation"
;
validator.ControlToValidate = editor.TextBoxControl.ID;
validator.ErrorMessage =
"*"
;
cell.Controls.Add(validator);
}
}
Let me know if any concern.
Thanks,
Jayesh Goyani
0
Twan
Top achievements
Rank 1
answered on 18 Jul 2013, 11:57 AM
This described solution is broken when upgrading from 2012.4.411.40 to 2013.2.717.40.
A follow up call (OnDataBind) will throw Object reference not set to instance of an object.
A follow up call (OnDataBind) will throw Object reference not set to instance of an object.
0
Shinu
Top achievements
Rank 2
answered on 18 Jul 2013, 12:18 PM
Hi,
The above code snippet is for versions before Q1 2013.So please try the below code snippet.
ASPX:
C#:
You can also have a look at this documentation on Validation.
Thanks,
Shinu
The above code snippet is for versions before Q1 2013.So please try the below code snippet.
ASPX:
<
telerik:GridBoundColumn
DataField
=
"ShipCity"
HeaderText
=
"ShipCity"
UniqueName
=
"ShipCity"
/>
C#:
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = e.Item
as
GridEditableItem;
GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor(
"ShipCity"
);
TableCell cell = (TableCell)editor.TextBoxControl.Parent;
RequiredFieldValidator validator =
new
RequiredFieldValidator();
validator.ControlToValidate = editor.TextBoxControl.ID;
validator.ErrorMessage =
"*"
;
cell.Controls.Add(validator);
}
You can also have a look at this documentation on Validation.
Thanks,
Shinu
0
Twan
Top achievements
Rank 1
answered on 18 Jul 2013, 12:26 PM
That C# code is what is causing the bug not the .aspx
0
Shinu
Top achievements
Rank 2
answered on 19 Jul 2013, 03:12 AM
Hi Twan
The C# code was working fine at my end,have you tried the same code.The version im using is 2013.2.611.40.Please try the code in the documentation for the latest version.There are two codes for versions before Q1 2013 and after.So make sure you have used the right code.
If this doesn't help,please provide your full code.
Thanks,
Shinu
The C# code was working fine at my end,have you tried the same code.The version im using is 2013.2.611.40.Please try the code in the documentation for the latest version.There are two codes for versions before Q1 2013 and after.So make sure you have used the right code.
If this doesn't help,please provide your full code.
Thanks,
Shinu
0
Twan
Top achievements
Rank 1
answered on 25 Apr 2014, 10:26 AM
Hey,
I have found the problem in our code. In a previous implementation it was recommended to set the id of the column editor in order for the required field validator to work. It was a line like this:
The same goes for DropDown editor. Removing this line fixed the issue.
Regards,
Twan
I have found the problem in our code. In a previous implementation it was recommended to set the id of the column editor in order for the required field validator to work. It was a line like this:
editor.TextBoxControl.ID = "someId";
The same goes for DropDown editor. Removing this line fixed the issue.
Regards,
Twan
0
Mohd
Top achievements
Rank 1
answered on 07 Oct 2015, 08:29 AM
<telerik:GridTemplateColumn HeaderText="Completion Date" UniqueName="CompletionDate"
DataType="System.DateTime" SortExpression="CompletionDate">
<ItemTemplate>
<asp:Label runat="server" ID="CompletionDateLabel" DataFormatString="{0:d}" Text='<%# Eval("CompletionDate") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="CompletionDatePicker" runat="server" DbSelectedDate='<%# Bind("CompletionDate") %>'>
</telerik:RadDatePicker>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
ControlToValidate="CompletionDatePicker"></asp:RequiredFieldValidator>
</EditItemTemplate>
</telerik:GridTemplateColumn>
This works for me
DataType="System.DateTime" SortExpression="CompletionDate">
<ItemTemplate>
<asp:Label runat="server" ID="CompletionDateLabel" DataFormatString="{0:d}" Text='<%# Eval("CompletionDate") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="CompletionDatePicker" runat="server" DbSelectedDate='<%# Bind("CompletionDate") %>'>
</telerik:RadDatePicker>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
ControlToValidate="CompletionDatePicker"></asp:RequiredFieldValidator>
</EditItemTemplate>
</telerik:GridTemplateColumn>
This works for me
0
Mohd
Top achievements
Rank 1
answered on 07 Oct 2015, 08:30 AM
<telerik:GridTemplateColumn HeaderText="Completion Date" UniqueName="CompletionDate"
DataType="System.DateTime" SortExpression="CompletionDate">
<ItemTemplate>
<asp:Label runat="server" ID="CompletionDateLabel" DataFormatString="{0:d}" Text='<%# Eval("CompletionDate") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="CompletionDatePicker" runat="server" DbSelectedDate='<%# Bind("CompletionDate") %>'>
</telerik:RadDatePicker>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
ControlToValidate="CompletionDatePicker"></asp:RequiredFieldValidator>
</EditItemTemplate>
</telerik:GridTemplateColumn>
DataType="System.DateTime" SortExpression="CompletionDate">
<ItemTemplate>
<asp:Label runat="server" ID="CompletionDateLabel" DataFormatString="{0:d}" Text='<%# Eval("CompletionDate") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="CompletionDatePicker" runat="server" DbSelectedDate='<%# Bind("CompletionDate") %>'>
</telerik:RadDatePicker>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
ControlToValidate="CompletionDatePicker"></asp:RequiredFieldValidator>
</EditItemTemplate>
</telerik:GridTemplateColumn>