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

[Solved] Expand column width problem

3 Answers 279 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mats
Top achievements
Rank 1
Mats asked on 25 Jun 2009, 02:30 PM
Hi!

My problem is that when I have a wide control (for example a TextBox that is 500px wide) in the CommandItemTemplate then the width of the ExpandColumn will increase.

There is changed behaviour in Q1 2009 making the expand column width to be dependent on content of CommandItemTemplate.

Does anyone have a clue how to set a fixed size for the ExpandColumn in this case? I have tried to set width property in css for rgExpandCol but it does not work for me.

Thanks
/Mats

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jun 2009, 06:32 AM
Hello Mats,

Which version of RadGrid are you using? I'm using the 2009.1.311.20 version and i could not replicate the issue. You can set the width of the Expand column in the grid to a fixed value using the following code:
c#:
 protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    { 
        if (e.Column is GridExpandColumn) 
        { 
            e.Column.HeaderStyle.Width = new Unit(60); 
            e.Column.ItemStyle.Width = new Unit(60); 
        }   
    } 

Thanks
Princy.
0
Mats
Top achievements
Rank 1
answered on 26 Jun 2009, 08:18 AM
Hi Princy,

Thanks for your quick answer. The version I use is 2009.1.527.20. But I have tried earlier versions of 2009.1 with the same result.
Adding your code to my project makes no difference to the visual rendered result. I can see in the html source that the width style is applied but it does not visually change anything.

I append here my (simplified) default.aspx for replicating the problem:

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
            <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" 
                OnNeedDataSource="RadGrid1_NeedDataSource" OnColumnCreated="RadGrid1_ColumnCreated">  
                <MasterTableView CommandItemDisplay="Top">  
                    <DetailTables> 
                        <telerik:GridTableView runat="server" DataMember="Detail">  
                        </telerik:GridTableView> 
                    </DetailTables> 
                    <ExpandCollapseColumn Visible="True">  
                    </ExpandCollapseColumn> 
                    <CommandItemTemplate> 
                            <asp:TextBox ID="TextBox1" runat="server" Width="500px"></asp:TextBox> 
                    </CommandItemTemplate> 
                </MasterTableView> 
            </telerik:RadGrid> 
    </form> 
</body> 
<script language="C#" runat="server">  
    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    {  
        ArrayList l = new ArrayList();  
        l.Add("One");  
        l.Add("Two");  
        l.Add("Three");  
        ((RadGrid)source).DataSource = l;  
    }  
 
    protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)  
    {  
        if (e.Column is GridExpandColumn)  
        {  
            e.Column.HeaderStyle.Width = new Unit(20);  
            e.Column.ItemStyle.Width = new Unit(20);  
        }  
    }  
</script> 
</html> 
 

Interesting is that there must be some change from 2008 to 2009 since I never had this problem before.

Thanks
Mats
0
Dimo
Telerik team
answered on 30 Jun 2009, 12:33 PM
Hello Mats,

Thanks for providing a sample page.

Please set TableLayout="Fixed" for the MasterTableView and the ExpandColumn will shrink to its normal width. By the way, I don't see a difference in the RadGrid behavior in this case when testing with versions Q1 2009 and Q3 2008.

Regards,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Mats
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mats
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or