Telerik UI ASP.net RADGRID以编程方式设置列宽

时间:2014-02-26 14:28:16

标签: asp.net vb.net telerik radgrid

我正在尝试在项目中显示Telerik RadGrid。 我有一个更改列宽的问题。 我的网格的数据源是一个对象列表。 当我向网格添加过滤器时,列的宽度是固定的,我无法更改它/调整大小。

P.S。我想以编程方式(在vb代码中)解决此问题

我的vb代码:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
      setColumnsOnGrid(Of object)(lst, RadGrid1, ArrayNameFilds:={"column1", "column2", "column3 ", "etc."})
    End If
End Sub


Private Sub setColumnsOnGrid(Of T)(ByVal lst As List(Of T), ByVal grdName As RadGrid, ByVal ArrayNameFilds As Array)
    Dim nameFiled As String
    grdName.DataSource = lst
    grdName.AllowMultiRowSelection = True
    grdName.MasterTableView.AutoGenerateColumns = False

    Dim boundColumn As GridBoundColumn

    For i As Integer = 0 To ArrayNameFilds.Length - 1
        nameFiled = ArrayNameFilds(i).ToString()
        boundColumn = New GridBoundColumn()
        grdName.MasterTableView.Columns.Add(boundColumn)
        boundColumn.DataField = nameFiled
        boundColumn.HeaderText = nameFiled
     Next
End Sub

我的aspx:

 <telerik:RadGrid ID="grd_test" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" CellSpacing="0" GridLines="None">
    <ClientSettings>
        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
    </ClientSettings>
</telerik:RadGrid>

1 个答案:

答案 0 :(得分:0)

我在telerik论坛上找到了答案:

grdName.MasterTableView.Columns(i).HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(50)
grdName.MasterTableView.Columns(i).FilterControlWidth = System.Web.UI.WebControls.Unit.Pixel(50)

您还可以使用百分比:

System.Web.UI.WebControls.Unit.Percentage