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

[Solved] Get the WIDTH of a RadGrid - Colum

6 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laz
Top achievements
Rank 1
Laz asked on 25 Jun 2009, 09:03 AM

Hi to all,

it is possible to get the WIDTH of a RadGrid - Colum by Serverside or ClientSide!

I would like to set the WIDTH for a RadComboBox that is equal to the WIDTH to the RadGrid Column.

For visual reasons, I would like to set the width for the RadComboBox equal to column size

Thank

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Jun 2009, 10:27 AM
Hi Laz,

One sugestion is setting the Width of RadComboBox to "100%" so that the combobox will take the width of container accordingly.

ASPX:
 
<telerik:GridTemplateColumn UniqueName="Combo">  
    <ItemTemplate> 
        <telerik:RadComboBox ID="RadComboBox2" runat="server" Width="100%">  
        </telerik:RadComboBox> 
    </ItemTemplate>       
</telerik:GridTemplateColumn> 

Thanks,
Princy.
0
Laz
Top achievements
Rank 1
answered on 25 Jun 2009, 10:40 AM
Hi Princy,

sorry i think my description was not the best!

My RadComboBox is not inside the RadGrid. It is outside in a RadToolBar!
Thanks
0
Princy
Top achievements
Rank 2
answered on 25 Jun 2009, 01:02 PM
Hi Laz,

Try the following code snippet and see whether it helps.

ASPX:
 
<telerik:RadToolBar ID="RadToolBar1" runat="server">  
    <Items> 
        <telerik:RadToolBarButton runat="server" Text="Button 0">  
            <ItemTemplate> 
                <telerik:RadComboBox ID="RadComboBox3" runat="server">  
                    <Items> 
                      . . .  
                    </Items> 
                </telerik:RadComboBox> 
            </ItemTemplate> 
        </telerik:RadToolBarButton> 
        . . .  
    </Items> 
</telerik:RadToolBar> 

CS:
 
    int w = Convert.ToInt32(RadGrid1.MasterTableView.GetColumn("Combo").HeaderStyle.Width.Value); // Get the width of grid column  
    RadToolBarItem Item = (RadToolBarItem) RadToolBar1.FindItemByText("Button 0"); // Get the ToolBar item  
 
    RadComboBox combo = (RadComboBox)Item.FindControl("RadComboBox3"); // Get reference to combobox  
    combo.Width = Unit.Pixel(w); // Set width 

Thanks,
Princy.
0
Laz
Top achievements
Rank 1
answered on 25 Jun 2009, 01:34 PM
Unfortunately, the expression always returns 0

int w = Convert.ToInt32(RadGrid1.MasterTableView.GetColumn("Combo").HeaderStyle.Width.Value); 
0
Princy
Top achievements
Rank 2
answered on 26 Jun 2009, 06:03 AM
Hi Laz,

Unless, until you set the width of the column explicitly, the width of the column will be 0. So, a possible suggestion for your scenario is to set the width of the grid column explicitly and then set the same width value for the RadComboBox in the aspx.
aspx:
<telerik:GridBoundColumn DataField="ProductName" UniqueName="BoundColumn" HeaderText="BoundColumn"
   <HeaderStyle Width="100px" /> 
</telerik:GridBoundColumn> 
 
 
<telerik:RadToolBar ID="RadToolBar1" runat="server">   
    <Items>  
        <telerik:RadToolBarButton runat="server" Text="Button">   
            <ItemTemplate>  
                <telerik:RadComboBox ID="RadComboBox3" Width="100px" runat="server">   
                    ... 
                </telerik:RadComboBox>  
            </ItemTemplate>  
        </telerik:RadToolBarButton>  
        . . .   
    </Items>  
</telerik:RadToolBar>  

Thanks
Princy.
0
Laz
Top achievements
Rank 1
answered on 26 Jun 2009, 07:52 AM

Hi,

this work. BUT unfortunately it does not solve my problem.

It does not solve my problem because I can not specify the width as I do not know it?

Because of this i can not define the <HeaderStyle Width="100px" />.

That is why I have this work leave the grid. This automatically defines the optimal colum width. I hope that when the grid set the optimal width depending on the text length, that i can get it to set it for the RadComboBox!

Is there a way to get the width without define a HeaderStyle.

Regards

Tags
Grid
Asked by
Laz
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Laz
Top achievements
Rank 1
Share this question
or