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

How do I set width only for one column without using tablelayout=fixed

2 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nirav
Top achievements
Rank 1
Nirav asked on 26 Jan 2011, 06:45 PM
Hi,
I am using Telerik RadGrid and displaying about 15 columns.
Now I want to set width for a particular column, not for all columns.
I tried giving HeaderStyle width but somehow its not changing width.
If I use TableLayout="Fiexed", I will have to set all the columns width and also it cut out rest of the words.
And actually depending upon my columns, I prefer not to set width for columns but I just want to set width for one single column.

Here is my code and I want to set width for "rejectrequest" column only.
Want to have every other column as auto width which is working fine.
NOTE: In my sample code, I have not added all of my columns. Added few columns only but actually I have more columns than this.

<div class="Scrollgrid" style="width: 1100px; height: 600px;">
                                                <telerik:RadGrid ID="RadGridAllRequests" runat="server" AllowPaging="true" AllowSorting="true"
                                                    AllowFilteringByColumn="true" AutoGenerateColumns="False" GridLines="Both" OnNeedDataSource="RadGridAllRequests_needdatasource"
                                                    OnItemDataBound="RadGridAllRequests_ItemDataBound" 
                                                    OnItemCreated="RadGridAllRequests_ItemCreated"
                                                    OnItemCommand="RadGridAllRequests_ItemCommand"
                                                    AllowMultiRowSelection="true" SelectedItemStyle-CssClass="SelectedItem" 
                                                       
                                                    Width="100%"
                                                    Skin="WebBlue">
                                                    <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="TopAndBottom" AlwaysVisible="true" />
                                                    <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
                                                        <Selecting AllowRowSelect="true" />
                                                    </ClientSettings>
                                                      
                                                    <MasterTableView ShowHeadersWhenNoRecords="true" 
                                                    AllowFilteringByColumn="true" DataKeyNames="RequestInfoID">
                                                        <Columns>
                                                            <telerik:GridNumericColumn DataField="RequestInfoID" HeaderText="Request No." SortExpression="RequestInfoID"
                                                                DataType="System.Int64" FilterControlWidth="40px" 
                                                                HeaderStyle-Width="100px"                                                                
                                                                >
                                                            </telerik:GridNumericColumn>
                                                            <telerik:GridDateTimeColumn 
                                                            HeaderStyle-Width="130px"     
                                                            DataField="CreationDate" HeaderText="Created On" FilterControlWidth="100px"
                                                                CurrentFilterFunction="Contains" PickerType="DatePicker" DataFormatString="{0:MM/dd/yyyy}"
                                                                SortExpression="CreationDate">
                                                            </telerik:GridDateTimeColumn>
                                                            <telerik:GridNumericColumn DataField="TotalAmount" HeaderText="Total Amount" SortExpression="TotalAmount"
                                                                HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" DataType="System.Decimal"
                                                                FilterControlWidth="70px" DataFormatString="{0:#,##0.00}">
                                                                <FooterStyle Font-Bold="true" />
                                                            </telerik:GridNumericColumn>
                                                            <telerik:GridBoundColumn DataField="RequestedFrom_Email" HeaderText="Requested From"
                                                                SortExpression="RequestedFrom_Email">
                                                            </telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Describe Reason and Reject" UniqueName="rejectrequest"
                                                               
                                                                AllowFiltering="false"  
                                                                HeaderStyle-Width="240px" >
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lblNextApprovalRequiredFor" runat="server" Visible="false" Text='<%#Eval ( "NextApprovalRequiredFor").ToString()%>'></asp:Label>
                                                                    <asp:Label ID="lblUnder5000ApprovedORRejected" runat="server" Visible="false" Text='<%#Eval ( "Under5000ApprovedORRejected").ToString()%>'></asp:Label>
                                                                    <asp:Label ID="lblOver5000ApprovedORRejected" runat="server" Visible="false" Text='<%#Eval ( "Over5000ApprovedORRejected").ToString()%>'></asp:Label>
                                                                    <asp:Label ID="lblFinanceApprovedORRejected" runat="server" Visible="false" Text='<%#Eval ( "FinanceApprovedORRejected").ToString()%>'></asp:Label>
                                                                    <asp:Label ID="lblOver25000CFOApprovedORRejected" runat="server" Visible="false"
                                                                        Text='<%#Eval ( "Over25000CFOApprovedORRejected").ToString()%>'></asp:Label>
                                                                    <asp:Label ID="lblOver25000COOApprovedORRejected" runat="server" Visible="false"
                                                                        Text='<%#Eval ( "Over25000COOApprovedORRejected").ToString()%>'></asp:Label>
                                                                    <asp:Label ID="lblOver25000CEOApprovedORRejected" runat="server" Visible="false"
                                                                        Text='<%#Eval ( "Over25000CEOApprovedORRejected").ToString()%>'></asp:Label>
                                                                    <asp:Label ID="lblRejectedMessage" runat="server" Text="Rejected"></asp:Label>
                                                                    <asp:TextBox Width="150px" runat="server" MaxLength="150" ValidationGroup="vgRejection"
                                                                        ID="txtRejectionReason" ToolTip="Enter Rejection Reason"></asp:TextBox>
                                                                    <%--                                                            <asp:RequiredFieldValidator 
                                                                ID="rvRejectionReason" 
                                                                Display="Dynamic"
                                                                ValidationGroup="vgRejection"
                                                                runat="server" 
                                                                SetFocusOnError="true"
                                                                ControlToValidate="txtRejectionReason" 
                                                                ErrorMessage="Enter Rejection Reason" 
                                                                ToolTip="Enter Rejection Reason">
                                                            </asp:RequiredFieldValidator>                        
--%>
                                                                    <asp:Button  CssClass="ButtonCSS" 
                                                                    runat="server" ID="btnRejectRequest" Text="Reject" 
                                                                    ToolTip="Click here to Reject Request"
                                                                    CausesValidation="true" ValidationGroup="vgRejection" OnClick="btnRejectRequest_Click"
                                                                    OnClientClick="javascript:var agree= confirm('Are you sure you want to reject this Request? '); if(agree){ Page_BlockSubmit = false;buttonClicked_WithObj(this); return true; };else {return false;};"
                                                                    CommandArgument='<%# 
                                                                Eval ( "RequestInfoID").ToString() 
                                                                + ";" +
                                                                Eval ( "NextApprovalRequiredFor").ToString() 
                                                                + ";" +
                                                                Eval ( "TotalAmount").ToString() 
                                                                  
                                                                %>' />
                                                                </ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                            <telerik:GridBoundColumn DataField="Request_Current_Status_DisplayText" HeaderText="Current Status"
                                                                SortExpression="Request_Current_Status_DisplayText" UniqueName="Request_Current_Status_DisplayText">
                                                            </telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Request No." SortExpression="RequestInfoID"
                                                                AllowFiltering="false" Visible="false" UniqueName="requestinfoid">
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lblRequestInfoID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "RequestInfoID")%>'></asp:Label></ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                        </Columns>
                                                        <EditFormSettings>
                                                            <PopUpSettings ScrollBars="None" />
                                                        </EditFormSettings>
                                                        <ExpandCollapseColumn Resizable="False" Visible="False">
                                                            <HeaderStyle />
                                                        </ExpandCollapseColumn>
                                                        <RowIndicatorColumn Visible="False">
                                                            <HeaderStyle />
                                                        </RowIndicatorColumn>
                                                    </MasterTableView>
                                                </telerik:RadGrid>
                                            </div>

Thanks in advance ,


2 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 27 Jan 2011, 08:23 AM
Hello Nirav,

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

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.
0
Nirav
Top achievements
Rank 1
answered on 27 Jan 2011, 04:25 PM
Thanks for sharing this.
I found solution.
I added a Table inside ItemTemplate and gave width to whatever I want and placed my controls inside that Table and that worked fine.

Thanks again
Tags
Grid
Asked by
Nirav
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Nirav
Top achievements
Rank 1
Share this question
or