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

Rad Grid Column Width

11 Answers 529 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrey
Top achievements
Rank 1
Andrey asked on 30 Mar 2011, 08:42 AM
I have Rad Grid with template column(and an image inside), and i want that the width of this column be constant(in pixels).
I add this code-
protected void rgBase_PreRender(object sender, EventArgs e)
     {
         foreach (GridColumn col in rgBase.MasterTableView.RenderColumns)
         {
             if (col.UniqueName == "img_add")
             {
                 col.ItemStyle.Width = Unit.Pixel(20);
                 col.HeaderStyle.Width = Unit.Pixel(20);
             }
 
         }
     }

And it`s show fine on first page load, i also have grid width="100%", and when i resizing window my column "img_add" changing width,  i want that it`s width will be constant and on resizing window. How can i do this?

Andrey

11 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 30 Mar 2011, 10:09 AM
Hi Andrey,

Keep in mind that it is not recommended to use ItemStyle-Width to set column widths. Only HeaderStyle-Width should be used.

Regards,
Pavlina
the Telerik team
0
Andrey
Top achievements
Rank 1
answered on 30 Mar 2011, 10:22 AM
Thanks, but it`s not solved my problem.
0
Pavlina
Telerik team
answered on 04 Apr 2011, 01:06 PM
Hi Andrey,

I tried to reproduce the issue locally, but without success. Based on your code I have created a small sample that works as expected on my side. Please review it and let me know if you need additional assistance.

Best wishes,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andrey
Top achievements
Rank 1
answered on 05 Apr 2011, 10:55 AM
Hello,

Your example works, but if do this in your example
<telerik:GridBoundColumn DataField="ContactName" HeaderText="ContactName" >
                    <HeaderStyle Width="50" />
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Address" HeaderText="Address" >
                    <HeaderStyle Width="50" />
                </telerik:GridBoundColumn>

It stop working, the same problem in my project. I want thath firts column will be the constant width and other changing width depending on window size, but not smallest then an constant value. How can i do this?

Andrey.
0
Pavlina
Telerik team
answered on 06 Apr 2011, 04:32 PM
Hello Andrey,

I recommend that you go through the following forum thread for more information about column widths.
http://www.telerik.com/community/forums/aspnet/grid/best-practice-for-grid-and-column-widths.aspx

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jerry T.
Top achievements
Rank 1
answered on 18 Apr 2011, 02:57 PM
Pavlina.

Why isn't ItemStyle-Width used to set the control's width when in Insert/Edit mode (without us having to resort to using GridTemplateColumn)??

To me, that's what that attribute should be doing and that's what Telerik's developers need to have that attribute do.  It's fine to use HeaderStyle-Width to set the column width but have ItemStyle-Width set the control's width when editing/inserting (like the ControlStyle attributes in .Net's GridView control)

Jerry
0
Pavlina
Telerik team
answered on 20 Apr 2011, 09:37 AM
Hello Jerry,

I am not aware of cases in which ItemStyle-Width should be used at all. This property exists only because ItemStyle inherits from TableItemStyle.

For column widths, please use HeaderStyle-Width only.

Regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jerry T.
Top achievements
Rank 1
answered on 20 Apr 2011, 01:32 PM
Pavlina,

Yes, I understand to use HeaderStyle-Width to set the column width.

What I'm *asking*, though, is why can't ItemStyle-Width be used to set the *control's* width inside the column?  The attribute is there, make use of it!  I *hate* having to use a GridItemTemplateColumn (or even worse, going into the codebehind) in order to set a control's width. This seems like a rather obvious and simple feature for the developers to add to the RadGrid control.

Jerry
0
Pavlina
Telerik team
answered on 25 Apr 2011, 12:54 PM
Hi Jerry T.,

You can set the control's width when in Insert/Edit mode as shown below:
C#
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);   
      }    
           
  }

Or you can set column editors for various columns and set their styles declaratively. Refer to the following help document for more information:
Declarative style editors

Best wishes,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jerry T.
Top achievements
Rank 1
answered on 25 Apr 2011, 01:32 PM
Right,

I understand I *can* do it in the codebehind but it would be very nice if there was an attribute that could be set in the markup to set the control's width (like the ControlStyle attributes in the built-in GridView control)

Jerry
0
Pavlina
Telerik team
answered on 25 Apr 2011, 01:55 PM
Hi Jerry,

Thank you for your feedback. I will forward this request to our developers for further consideration.

All the best,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Andrey
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Andrey
Top achievements
Rank 1
Jerry T.
Top achievements
Rank 1
Share this question
or