我正在尝试在项目中的Telerik 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 :(得分:0)
如果需要绑定到boolean类型的对象,则必须添加GridCheckBoxColumn
,我不在此处放置示例,因为它与您的奇怪页面逻辑相关。
您可以在这里找到更多参考资料: http://www.telerik.com/help/aspnet-ajax/grid-column-types.html#checkbox
答案 1 :(得分:0)
我找到了解决方案(基于Bujutsu的答案):
VB.NET代码:
'add check box column
Dim objGridClientSelectColumn As GridClientSelectColumn = New GridClientSelectColumn()
objGridClientSelectColumn.UniqueName = "UniqueName"
Grid.MasterTableView.Columns.Add(objGridClientSelectColumn)