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

Help setting MaxLength

2 Answers 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christopher
Top achievements
Rank 1
Christopher asked on 30 Oct 2015, 03:07 PM

Hi

 I'm trying to set the MaxLength of TextBoxes in GridBoundColumn.

 I get null for the Textbox...what am I doing wrong?

Code is below, thanks!

 

<telerik:RadGrid ID="grdUser" runat="server" CellSpacing="0" AutoGenerateColumns="False"
Width="95%" ShowStatusBar="True" OnInsertCommand="grdUser_InsertCommand" OnUpdateCommand="grdUser_UpdateCommand"
PageSize="20" AllowPaging="True" OnNeedDataSource="grdUser_NeedDataSource"
OnPreRender="grdUser_PreRender"
OnItemDataBound="grdUser_ItemDataBound"
GridLines="Horizontal">
<PagerStyle Mode="NextPrev"></PagerStyle>
<ClientSettings>
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView InsertItemPageIndexAction="ShowItemOnCurrentPage" EditMode="InPlace" CommandItemDisplay="Top" PagerStyle-Position="Bottom">
<CommandItemTemplate>
<div style="padding: 5px 5px;">
<asp:LinkButton ID="lnkBtnNew" CssClass="buttonClass" runat="server" CommandName="InitInsert"
Visible='<%# !grdUser.MasterTableView.IsItemInserted %>'>New</asp:LinkButton>&nbsp;&nbsp;
</div>
</CommandItemTemplate>
<Columns>
<telerik:GridBoundColumn DataField="UserID" HeaderText="User Id" UniqueName="UserID" Visible="false" />
<telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" UniqueName="FirstName" />
<telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" UniqueName="LastName" />
<telerik:GridBoundColumn DataField="LoginID" HeaderText="Login ID" UniqueName="LoginID" />
<telerik:GridCheckBoxColumn DataField="Active" HeaderText="Active" UniqueName="Active" />
<telerik:GridBoundColumn DataField="CreateUser.UserID" HeaderText="CreateUser.UserID" UniqueName="CreateUserID" Visible="false" />
<telerik:GridBoundColumn DataField="CreatedDate" DataType="System.DateTime" HeaderText="CreatedDate" UniqueName="CreatedDateLabel" ReadOnly="true" />
<telerik:GridBoundColumn DataField="CreatedDate" DataType="System.DateTime" HeaderText="CreatedDate" UniqueName="CreatedDate" Visible="false" />
<telerik:GridBoundColumn DataField="ChangeUser.UserID" HeaderText="ChangeUser.LoginID" UniqueName="ChangeUserID" Visible="false" ReadOnly="true" />
<telerik:GridBoundColumn DataField="ChangedDate" DataType="System.DateTime" HeaderText="ChangedDate" UniqueName="ChangedDate" ReadOnly="true" />
<telerik:GridEditCommandColumn />
</Columns>
</MasterTableView>
</telerik:RadGrid>

 

 

protected void grdUser_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
                    var d = UIProcess.UserGetAllColumnLengths();
var t = ((GridEditableItem)e.Item).FindControl("FirstName");

// t is NULL!
if (t != null)
(e.Item.FindControl("FirstName") as TextBox).MaxLength = d["FirstName"] ?? 0;
                   
                }
}
           

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 03 Nov 2015, 07:22 AM
Hi Christopher,

I noticed that you are using the InPlace editing mode. In that case, you will need to use the respective approach from the following section:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

Hope this helps.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Christopher
Top achievements
Rank 1
answered on 03 Nov 2015, 10:01 PM
Ahh that works, very helpful thanks!
Tags
Grid
Asked by
Christopher
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Christopher
Top achievements
Rank 1
Share this question
or