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

[Solved] Tip: adjusting textbox width W/auto generated forms

1 Answer 162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ayman Hamdan
Top achievements
Rank 1
Ayman Hamdan asked on 11 Jun 2008, 11:28 PM
Hi,
please remove this post if someone else had already posted it in this forum.  OR, if you think my post is not best practice/recomended.  I was looking for an easy way to adjust my textboxes width in an automatic edit generated form.  While I found answers that requires little more work, I was able to figure out an easier way to acheive that without writing to much code.  I hope that this code will help others who are/were in the same situation like me.

************

Imports

Telerik.Web.UI

....

Private
Sub GridUnits_CreateColumnEditor(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCreateColumnEditorEventArgs) Handles GridUnits.CreateColumnEditor

If IsNumeric(Right(e.Column.UniqueName, 3)) Then

Dim tbwidth As Integer

tbwidth =

CType(Right(e.Column.UniqueName, 3), Integer)

Dim tbGeneric = DirectCast(e.ColumnEditor, GridTextBoxColumnEditor)

tbGeneric.TextBoxControl.Width = Unit.Pixel(tbwidth)

End If

End Sub

***************************
All you have to do is to add three digit number to each uniquename property for the columns you wish to overwrite its width

<telerik:GridBoundColumn DataField="TabNo" DataType="System.Int32" HeaderText="TabNo"

SortExpression="TabNo" UniqueName="TabNo" Visible="False">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn DataField="Icon_url" HeaderText="Icon_url" SortExpression="Icon_url"

UniqueName="Icon_url300" Visible="False">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn DataField="bgImage_url" HeaderText="bgImage_url" SortExpression="bgImage_url"

UniqueName="bgImage_url200" Visible="False">

</telerik:GridBoundColumn>


If you know of an easier way, please let me know



1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Jun 2008, 04:45 AM
Hi,

You can set the width of the TextBox in edit mode in the PreRender event also.

CS:
 protected void RadGrid1_PreRender(object sender, EventArgs e)  
    {  
        foreach (GridEditableItem edititem in RadGrid1.MasterTableView.GetItems(GridItemType.EditItem))  
        {  
            foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)  
            {  
                if (edititem.IsInEditMode)  
                {  
                    TextBox txtbx = (TextBox)edititem[col.UniqueName].Controls[0];  
                    txtbx.Width = Unit.Pixel(50);  
                }  
            }  
        }  
  } 


Princy.
Tags
Grid
Asked by
Ayman Hamdan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or