This is a migrated thread and some comments may be shown as answers.

limit length on gridview column

1 Answer 298 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Donna
Top achievements
Rank 1
Donna asked on 12 Jun 2017, 02:47 PM

How can I limit the length of characters user can enter on a particular gridview column?

I tried this code but I got an error saying that there is no definition for MaxLength?

 

void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)     
{     
    if (e.ColumnIndex == 1)  
    {  
        if (e.Column is GridViewTextBoxColumn)     
        {     
            ((RadTextBoxEditorElement)((RadTextBoxEditor)this.radGridView1.ActiveEditor).EditorElement).MaxLength = 30;     
        }     
    }  

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 Jun 2017, 07:56 AM
Hello Donna,

Here is how you can set the MaxLength:
private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    var editor = e.ActiveEditor as RadTextBoxEditor;
    if (editor != null)
    {
        var element = editor.EditorElement as RadTextBoxEditorElement;
        element.TextBoxItem.MaxLength = 30;
    }
}

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Donna
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or