So how to do it ? in a simple declarative way for textboxes when using EditMode="EditForms"It seems that this is an important feature that should be easy to set declaratively in the *.aspx file....
If it's not possible, then I hope the next release will add this important feature!!!
4 Answers, 1 is accepted
You can set the width of the textbox of a Grid bound column in edit mode in the code behind as shown below.
CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) |
{ |
if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) |
{ |
GridEditFormItem editItem = (GridEditFormItem)e.Item; |
TextBox txtbx = (TextBox)editItem["columnUniqueName"].Controls[0]; |
txtbx.Width = Unit.Pixel(150); |
} |
} |
Other suggestion will be to use column editors so that you can set its width declaratively also.
Custom editors extending auto-generated editors
Declarative style editors
Thanks
Shinu.
But I want to suggest again that a new feature be added to the next release. It just should not take so many extra steps for the developer to write code just to adjust the size of a textbox in a datagrid.
telerik:GridBoundColumn does have a declarative attribute for MaxLength so it should also have a declarative attribute for Columns (that corresponds to a TextBox.Columns) so that it is just as easy to set the display number of characters as it is to set the maxlength number of characters for a datafield shown as a textbox in the datagrid.
I hope that this feature can be added to the next release.
Currently we do not plan to expose such a property. However, you can set the style of column editor in the markup as shown below:
Sample RadGrid definition
<telerik:RadGrid runat="server" ID="RadGrid1" |
AutoGenerateColumns="false" |
OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateEditColumn="true"> |
<MasterTableView DataKeyNames="ID"> |
<Columns> |
<telerik:GridBoundColumn DataField="ID" HeaderText="ID"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Text" |
HeaderText="Text" ColumnEditorID="MyEditor"> |
</telerik:GridBoundColumn> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
RadGrid declarative textbox style editor
<telerik:GridTextBoxColumnEditor runat="server" ID="MyEditor"> |
<TextBoxStyle Width="50px" /> |
</telerik:GridTextBoxColumnEditor> |
Best regards,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Protected Sub RadGrid1_PreRender1(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
What I did was set the maxlength for every textbox in the Rad Grid. You can then loop through each textbox and set the size * 7 which works out to the correct size in pixels.
Protected Sub RadGrid1_PreRender1(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
For Each edititem As GridEditFormItem In RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)
For Each col As GridColumn In RadGrid1.MasterTableView.RenderColumns
If col.ColumnType = "GridBoundColumn" Then
If edititem.IsInEditMode Then
Dim txtbx As TextBox = DirectCast(edititem(col.UniqueName).Controls(0), TextBox)
If Val(txtbx.MaxLength) > 1 Then
Dim iWidth As Integer = txtbx.MaxLength * 7
If iWidth > 1000 Then
iWidth = 1000
End If
txtbx.Width = iWidth
End If
End If
End If
Next
Next
End Sub
Hope this helps.
Graham
http://www.northerncs.com