Question

I am trying to display a column of checkboxes in Telerik RadGrid in my project. The data source of my grid is a list of objects. How to do this programatically ?

p.s. an answer in any programming language will be appreciated

my code:

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

my 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>

Was it helpful?

Solution 2

I found the solution(base on Bujutsu's answer):

VB.NET Code:

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

OTHER TIPS

You must add a GridCheckBoxColumn if you need to bind to an object of type boolean, i don't put the example here because it's related to your strange page logic.

Here you can find more references: http://www.telerik.com/help/aspnet-ajax/grid-column-types.html#checkbox

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top