Rad Grid Column Width

12 posts, 0 answers
  1. Andrey
    Andrey avatar
    32 posts
    Member since:
    Jun 2010

    Posted 30 Mar 2011 Link to this post

    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
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 30 Mar 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andrey
    Andrey avatar
    32 posts
    Member since:
    Jun 2010

    Posted 30 Mar 2011 Link to this post

    Thanks, but it`s not solved my problem.
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 04 Apr 2011 Link to this post

    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
  6. Andrey
    Andrey avatar
    32 posts
    Member since:
    Jun 2010

    Posted 05 Apr 2011 Link to this post

    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.
  7. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 06 Apr 2011 Link to this post

    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
  8. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 18 Apr 2011 Link to this post

    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
  9. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 20 Apr 2011 Link to this post

    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.

  10. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 20 Apr 2011 Link to this post

    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
  11. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 25 Apr 2011 Link to this post

    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.

  12. Jerry T.
    Jerry T. avatar
    118 posts
    Member since:
    Jul 2012

    Posted 25 Apr 2011 Link to this post

    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
  13. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 25 Apr 2011 Link to this post

    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.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017