3 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 22 Nov 2012, 07:40 AM
Hi Fadi,
I guess you want to allow the characters C and D only in the one of the TextBox in RadGrid editform. Please check the following code I tried to allow only C and D in a boundcolumn of the RadGrid in editmode.
ASPX:
C#:
JS:
Hope this helps.
Regards,
Princy.
I guess you want to allow the characters C and D only in the one of the TextBox in RadGrid editform. Please check the following code I tried to allow only C and D in a boundcolumn of the RadGrid in editmode.
ASPX:
<
Columns
>
<
telerik:GridBoundColumn
HeaderText
=
"EmployeeID"
DataField
=
"EmployeeID"
UniqueName
=
"EmployeeID"
/>
</
Columns
>
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem eitem = (GridEditableItem)e.Item;
TextBox txt = (TextBox)eitem[
"EmployeeID"
].Controls[0];
txt.Attributes.Add(
"onkeypress"
,
"return checkYear('"
+ txt.ClientID +
"',event);"
);
}
}
JS:
<script type=
"text/javascript"
>
function
checkYear(obj, e) {
var
key;
if
(window.event)
key = window.event.keyCode;
//IE
else
key = e.charCode;
//firefox
if
(!((key == 67) || (key == 68))) {
if
(window.event) {
//IE
window.event.returnValue =
false
;
return
false
;
}
else
if
(e.stopPropagation) {
//firefox
e.stopPropagation();
e.preventDefault();
}
}
}
</script>
Hope this helps.
Regards,
Princy.
0

Fadi
Top achievements
Rank 1
answered on 23 Nov 2012, 07:31 AM
Thanks Princy,
Yes exactly what do i want is to allow user only writes C or D letters in the third column of RadGridView. But it is a Windows Form Application.
I have tried the below code, but it didn't work...
So how could i implement it?
Yes exactly what do i want is to allow user only writes C or D letters in the third column of RadGridView. But it is a Windows Form Application.
I have tried the below code, but it didn't work...
private void radGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
if (radGridView1.CurrentColumn.Index == 2)
{
if (e.KeyChar != 'C' || e.KeyChar != 'c' || e.KeyChar != 'd' || e.KeyChar != 'D')
e.Handled = true;
}
}
So how could i implement it?
0

Princy
Top achievements
Rank 2
answered on 23 Nov 2012, 08:17 AM
Hi Fadi,
If you are not using RadControls for ASP.NET AJAX, Please post this thread in the WinForms GridView forum.
Regards,
Princy.
If you are not using RadControls for ASP.NET AJAX, Please post this thread in the WinForms GridView forum.
Regards,
Princy.