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

Setting MaxLength of Edit Textboxes of Autogenerated columns

1 Answer 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kate
Top achievements
Rank 1
Kate asked on 01 Aug 2014, 01:59 PM
How do you set a MaxLength of edit textboxes at runtime if you don't know the control name? All my columns are autogenerated based on the dataset coming back from a stored proc. 

1 Answer, 1 is accepted

Sort by
0
Kate
Top achievements
Rank 1
answered on 01 Aug 2014, 02:57 PM
I found a solution after many hours of experimenting. Posting for anyone who has a similar issue.

protected void radDiscounts_ItemDataBound(object sender, GridItemEventArgs e)
 {
     if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
         //only affect columns 6 to the total number of dynamic columns
         for (int i = 5; i < e.Item.Controls.Count; i++)
         {
            //must first access the cell of the column, then access the textbox within the cell
            GridDataItem dataItem = (GridDataItem)e.Item;
            GridTableCell cell = (GridTableCell)dataItem.Controls[i];
            TextBox txtbx = (TextBox)cell.Controls[0];
            txtbx.MaxLength = 2;
         }
    }
}
Tags
Grid
Asked by
Kate
Top achievements
Rank 1
Answers by
Kate
Top achievements
Rank 1
Share this question
or