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

Textbox width in Edit Form

10 Answers 309 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eliyahu Goldin
Top achievements
Rank 1
Eliyahu Goldin asked on 28 Aug 2008, 09:49 AM
In the same grid, I have a GridBoundColumn with MaxLength="50" and another GridBoundColumn with MaxLength="6". On the Edit Form both columns are represented by textboxes of the same width which is too short for one of them and too long for another. Is there a way to control textbox width without turning the columns into GridTemplateColumns?

10 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 28 Aug 2008, 10:26 AM
Hi,

You can set the textbox width of the GridBoundColumn when it is in edit mode as shown below.

CS:
  protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditableItem edititem = (GridEditableItem)e.Item; 
            TextBox txtbx = (TextBox)edititem["ColumnUniqueName"].Controls[0]; 
            txtbx.Width = Unit.Pixel(100); 
        }  
         
    } 


Thanks
Shinu.
0
Eliyahu Goldin
Top achievements
Rank 1
answered on 28 Aug 2008, 04:55 PM
Thanks, this works fine for a particular column.

However, instead of individual coding for every column, I would've been happier with an ability to increase textbox width for all columns in the Edit Form Column or having a setting like "EnableAutosizingTextBoxes".

Telerik, is such a feature feasible?
0
Shinu
Top achievements
Rank 2
answered on 29 Aug 2008, 04:42 AM
Hi Eliyahu,

Try the following code snippet to set the textbox width of all GridBoundColumns in edit mode.

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


Thanks
Shinu.

0
Clive Hoggar
Top achievements
Rank 1
answered on 19 Dec 2008, 11:24 PM
Hi
Sorry to be a pain but someone give me this in VB instead?
I am not great at reading and converting C#
thanks
Clive
0
Steve Y
Top achievements
Rank 2
answered on 19 Dec 2008, 11:51 PM
Clive. You could try the online code converter that Telerik has.

click here to see how it works out...

Regards, Steve
0
Clive Hoggar
Top achievements
Rank 1
answered on 20 Dec 2008, 09:40 PM
Hi
Thanks for your reply.
The translator produced this, which looks OK:
Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs)
        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)
                        txtbx.Width = Unit.Pixel(100)
                    End If
                End If
            Next
        Next
    End Sub

Two errors in the synatx are highlghted by VWD:
1 ) Type 'GridEditFormItem' is not defined
2 ) Name GridItemType is not defined

Maybe some declaration missing, but I am not sure what/where to insert it.
I already have in the code behind a class like this
Partial Class folder1_folder2_folder3/_Default
    Inherits System.Web.UI.Page

Can tell me what is missing?

Thanks

Clive





0
Steve Y
Top achievements
Rank 2
answered on 20 Dec 2008, 09:48 PM
Do you have the Telerik stuff imported?

Imports Telerik.Web.UI

Sometimes VWD will help too. If you have something that doesn't have an Imports statement yet, if you right click on the underlined word you'll see a context menu. If it can work it out, you'll see Resolve in the list, highlight that and it'll show you the item to import and you can just click it to automatically have it insert the Imports statement. If it cannot work out where the word is declared, you won't see Resolve in the list.

Regards, Steve
0
Clive Hoggar
Top achievements
Rank 1
answered on 20 Dec 2008, 10:05 PM
Doh! That Homer Simpson moment...

That does it!

Thanks

Clive
0
Cyrus
Top achievements
Rank 1
answered on 25 Feb 2009, 05:37 PM
Why on earth is this not a property of the grid in the aspx? 
0
Princy
Top achievements
Rank 2
answered on 26 Feb 2009, 04:04 AM
Hello Cyrus,

You can set custom editors for columns and then set the width of the editors. You can refer to the following help link to understand how to add a column editor declaratively and set its properties.
Declarative style editors

Thanks
Princy.
Tags
Grid
Asked by
Eliyahu Goldin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Eliyahu Goldin
Top achievements
Rank 1
Clive Hoggar
Top achievements
Rank 1
Steve Y
Top achievements
Rank 2
Cyrus
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or