<telerik:RadGrid ID="grid_Historical_Commodity" runat="server" Visible="false" Width="995px" Height="450px" />
grid.Visible = True
grid.ClientSettings.Scrolling.UseStaticHeaders = True
grid.ClientSettings.Scrolling.AllowScroll = True
grid.ClientSettings.Resizing.AllowColumnResize = True
Dim rs As SqlDataReader = Nothing
rs = getdata()
Dim dt As Data.DataTable = New Data.DataTable
dt.Load(rs)
grid.DataSource = dt
how do i make it so that the content in certain columns are center and each column has a fixed size. thanks
9 Answers, 1 is accepted
Try setting CSS class for the columns from the ItemDataBound. Here is a sample code.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
item[
"ColUniqueName"
].CssClass =
"textCenter"
;
}
}
.textCenter
{
text-align
:
center
!important
;
}
For your second requirement set the TableLayout="Fixed"
aspx:
<
telerik:RadGrid
ID
=
"RadGrid3"
DataSourceID
=
"SqlDataSource3"
AutoGenerateColumns
=
"true"
AllowPaging
=
"True"
runat
=
"server"
>
<
HeaderStyle
Width
=
"100"
/>
<
MasterTableView
TableLayout
=
"Fixed"
>
....
Thanks,
Shinu.
what if i want to assign certain column to certain width, how would i do that on the server side? thanks.
You can set the column width in the PreRender as follows.
C#:
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
RadGrid1.MasterTableView.GetColumn(
"ColUniqueName"
).HeaderStyle.Width = Unit.Pixel(300);
}
Thanks,
Shinu.
Hi Telerik Team,
With respect to the above question, when I set the width to one column, it is setting up the similar column width to all the other columns present in the GRID.
I am using the latest telerik version 2016.1.113.45.
Please suggest what needs to be done.
When MasterTableView's TableLayout is switched to "Fixed" this will lead to all columns with no explicit width be equally wide and I suppose that this is the reason for the observed behavior. If you want to set specific column widths you need to set pixel widths to all grid columns.
Regards,
Pavlina
Telerik
Hi Pavilina,
Thanks for your quick response.
I am not setting the tablelayout to 'fixed'. I think by default the layout is 'Auto'.
<telerik:RadGrid ID="dgEscrow" runat="server" GridLines="None" EnableEmbeddedSkins="false" AutoGenerateColumns="false" ShowFooter="true" CssClass="esGridTable">
<HeaderStyle Font-Bold="true" HorizontalAlign="Center" />
<ClientSettings >
<ClientEvents OnGridCreated="setScrollerDimensionsEscrow" />
<Scrolling AllowScroll="true" SaveScrollPosition="true" />
</ClientSettings>
</telerik:RadGrid>
Code behind:
Protected Sub dgEscrow_PreRender(sender As Object, e As EventArgs) Handles dgEscrow.PreRender
Dim gridCol As GridColumn = dgEscrow.MasterTableView.GetColumn("File #_String")
gridCol.HeaderStyle.Width = Unit.Pixel(70)
End Sub
Let me know what else I need to do get this thing done.
By design, the MasterTableView's TableLayout will be switched to "Fixed" if you are using static headers and at least one column width is set.
Regards,
Pavlina
Telerik
So isn't there anyway by which we set width for few columns explicitly and the rest remains unchanged?
Because once I am setting column width to one column, rest all columns are getting squeezed.
As I said in one of the previous posts you need to set fixed width to all columns or leave them to auto size.
Regards,
Pavlina
Telerik