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

Column Width at runtime for RadGrid

3 Answers 272 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 22 May 2008, 10:26 AM
Hi,

I have a RadGrid whose Columns may vary based on the criteria. Based on the column displayed the width is being set by getting the values from the Xml.
The columns width are setting fine when the grid is in display Mode.
On Edit mode what ever i set the width of the column it is set the TextBoxEditor width that is displayed in the columns.

I DONT want to change the textbox width, but want to reduce the column width at runtime.
Is there some property that needs to be set to override on the textbox.

I can achieve this if i manually resize the column width.
Help me out how this can be achieved

Thanks
Daniel

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 May 2008, 11:42 AM
Hi Daniel,

Try the following code snippet  in the PreRender event to set the column width.

CS:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns) 
        { 
            if (col.UniqueName == "ProductName") 
            { 
                col.ItemStyle.Width = Unit.Pixel(50); 
                col.HeaderStyle.Width = Unit.Pixel(50); 
            } 
          
        } 
    } 


Thanks
Shinu.
0
Daniel
Top achievements
Rank 1
answered on 23 May 2008, 03:38 AM
Shinu,

Thanks for that code snippet.

But it didnot work out. The column still remains to the width of the textboxeditor.
I think there is some other property missing ...


Thanks,
Daniel
0
Princy
Top achievements
Rank 2
answered on 23 May 2008, 10:13 AM
Hi,

Can you try decreasing the width of the TextBox in edit mode.

CS:
 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 txtbx = (TextBox)edititem["columnUniqueName"].Controls[0];  
            txtbx.Width = Unit.Pixel(50);  
        }  
   } 

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