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

Change Width Of GridBoundcolumn in PopUp Edit Mode

5 Answers 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric Turner
Top achievements
Rank 1
Eric Turner asked on 20 Apr 2010, 08:53 PM
I guess this is my stupid question week.  I have a Hierarchy Grid that has one detail grid.  That grid allows rows to be edited in PopUp Mode.  Before the PopUp is shown I want to increase the width of one of the gridboundcolumns that will appear on the PopUp..  I can get a handle to the field but cannot figure out how to change the width.  There is no width property available.  Code is posted below.  I have also tried the FindControl method used in other examples but cannot get a handle to it that way.  Can someone point me in the right direction?  Thanks

protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
        {            
             
            if ("Detail".Equals(e.Item.OwnerTableView.Name)) 
            {                 
                GridBoundColumn packageColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("PackageName") as GridBoundColumn; 
                GridBoundColumn fileIdColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("FileId") as GridBoundColumn; 
                GridBoundColumn connectionStringColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("ConnectionString") as GridBoundColumn;                 
                
                if (e.Item.IsInEditMode && e.Item is IGridInsertItem)                
                { 
                    (e.Item as GridEditableItem)["PackageName"].Enabled = true
                } 
                if ("InitInsert".Equals(e.CommandName)) 
                { 
                    packageColumn.ReadOnly = false
                    fileIdColumn.ReadOnly = false
                    connectionStringColumn.ItemStyle.Width = Unit.Pixel(200); //THIS IS THE FIELD I WANT TO CHANGE THE WIDTH OF                   
                } 
                else 
                { 
                    packageColumn.ReadOnly = true
                    fileIdColumn.ReadOnly = true
                }                 
            } 
        }         

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Apr 2010, 08:35 AM
Hello Eric,

You could access the TextBox control rendered in the Editform and set the width to required in ItemDataBound event 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 txtBox = (TextBox)edititem["connectionString"].Controls[0]; 
            txtBox.Width = Unit.Pixel(200);     // Set the width here   
        } 
    } 

Regards,
Shinu.

0
Eric Turner
Top achievements
Rank 1
answered on 21 Apr 2010, 01:16 PM
Thanks Shinu.  I was all around it but just couldn't get it right.  That worked great.
0
M
Top achievements
Rank 1
answered on 11 Oct 2012, 01:16 AM
I tried that and it didn't work.
What am I missing?

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 txtBox = (TextBox)edititem["Name"].Controls[0];
               txtBox.Width = Unit.Pixel(1400);     // Set the width here  
           }
       }
<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name column" HeaderText="Name" SortExpression="Name" UniqueName="Name">
                    <ItemStyle Width="150px"/>
                    <HeaderStyle Width="150px" />
                </telerik:GridBoundColumn>
0
Eyup
Telerik team
answered on 15 Oct 2012, 11:29 AM
Hello,

Could you please share which EditFormType you are currently using?

Please check out the following topic which demonstrates how to access controls in edit/insert mode:
( Section Accessing controls in edit/insert mode )
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

I hope this will prove helpful.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Senthilnathan
Top achievements
Rank 1
answered on 05 Jun 2013, 07:53 PM
Change 
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
to
if (e.Item is GridEditableItem && e.Item.IsInEditMode)

Code will look like
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
       {
           if (e.Item is GridEditableItem && e.Item.IsInEditMode)
           {
               GridEditableItem edititem = (GridEditableItem)e.Item;
               TextBox txtBox = (TextBox)edititem["Name"].Controls[0];
               txtBox.Width = Unit.Pixel(1400);     // Set the width here  
           }
       }

Tags
Grid
Asked by
Eric Turner
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Eric Turner
Top achievements
Rank 1
M
Top achievements
Rank 1
Eyup
Telerik team
Senthilnathan
Top achievements
Rank 1
Share this question
or