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

Set Column Width of RadGrid Items

4 Answers 711 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 07 Nov 2012, 03:47 PM
I am writing to ask how best column width can be set RadGrid Columns - either in C#, or .aspx;

Thanks in advance for any insight - best regards;
<telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="True" OnNeedDataSource="RadGrid2_NeedDataSource" AllowSorting="true" AllowFilteringByColumn="true" >
           <ClientSettings EnableRowHoverStyle="true">
               <Selecting AllowRowSelect="true" />
           </ClientSettings>
           <MasterTableView AllowMultiColumnSorting="True">
           
           </MasterTableView>
       </telerik:RadGrid>

public DataTable GetDataTable(string query)
    {
        String ConnString = "";
        //ConnString = ConfigurationManager.ConnectionStrings["CapacityManagement"].ConnectionString;
        ConnString = ConfigurationManager.ConnectionStrings[2].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(query, conn);
 
        DataTable myDataTable = new DataTable();
 
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }
 
        return myDataTable;
    }

protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
   {       
       (source as RadGrid).DataSource = GetDataTable("SELECT Date, Location, EquipmentType, InstalledPorts, UsedPorts, ReservedPorts, AvailablePorts, Utilization, ThreeMonthUtil, TwelveMonthUtil From tblSAMPortsLocationSummary");
   }

4 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Nov 2012, 04:36 PM
Hello,

Method : 1 -  by using below method if you want to change your column width in future then you can do it easily. I think it dose not matter you can assign in .aspx or .aspx.cs

but if we want to change this width in future then we can easily manage in .aspx with compare to .aspx.cs.

Add below class in your .css file.
.myclass
      {
          width: 100px;
      }

assign this class in to below column.
<telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                       <HeaderStyle CssClass="myclass" />
                       <ItemStyle CssClass="myclass" />
                   </telerik:GridBoundColumn>



Thanks,
Jayesh Goyani
0
Mohammad
Top achievements
Rank 1
answered on 10 Oct 2013, 05:00 AM
Not working... :(
0
Princy
Top achievements
Rank 1
answered on 10 Oct 2013, 05:52 AM
Hi Mohammad,

Please try setting the TableLayout of the radgrid to Fixed and check if it helps.

ASPX:
<MasterTableView TableLayout="Fixed" . . >

Thanks,
Princy
0
lv
Top achievements
Rank 1
answered on 09 Oct 2015, 08:13 AM
Thank you! It solved my problem.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Mohammad
Top achievements
Rank 1
Princy
Top achievements
Rank 1
lv
Top achievements
Rank 1
Share this question
or