2014-03-02 86 views
0

我想在我的項目中顯示一列Telerik RadGrid中的複選框。 我的網格的數據源是一個對象列表。 如何以編程方式執行此操作?Telerik UI ASP.net RADGRID以編程方式設置複選框的列

p.s. 任何編程語言的答案可以理解

我的代碼:

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>

回答

0

我找到了解決方案(上武術的答案基地):

VB.NET代碼:

'add check box column 
Dim objGridClientSelectColumn As GridClientSelectColumn = New GridClientSelectColumn() 
objGridClientSelectColumn.UniqueName = "UniqueName" 
Grid.MasterTableView.Columns.Add(objGridClientSelectColumn) 
0

必須,如果你需要綁定的對象添加一個GridCheckBoxColumn類型布爾值,我不把這個例子放在這裏,因爲它與你的奇怪的頁面邏輯有關。

在這裏你可以找到更多的參考資料: http://www.telerik.com/help/aspnet-ajax/grid-column-types.html#checkbox

+0

感謝,鏈接顯示瞭如何只在設計(ASPX)中執行此操作,而不是在代碼背後 – DUKEiLL

+0

快樂您找到解決方案! –

相關問題