I am trying to bind a RadGrid to a generic list of custom class through OnNeedDataSource. The grid displays the correct number of rows, however, the values for the fields are empty. I can bind to a datasource object without a problem, but I am going to be adding additional functionality where this method will be necessary. For simplicity sake, I am just trying to bind a single exposed property from the custom class object.
.ASPX
ASPX.VB
.ASPX
<form id="form1" runat="server"> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> </telerik:RadScriptManager> <div> <telerik:RadGrid runat="server" AllowPaging="True" ID="RadGrid2" OnNeedDataSource="RadGrid2_NeedDataSource" Width="600px" PageSize="8"> <MasterTableView Width="100%" > <Columns> <telerik:GridBoundColumn HeaderText="Project Name" DataField="name" ></telerik:GridBoundColumn> </Columns> <NoRecordsTemplate> <div style="height: 30px; cursor: pointer;"> No items to view</div> </NoRecordsTemplate> <PagerStyle Mode="NumericPages" PageButtonCount="4" /> </MasterTableView> </telerik:RadGrid> </div> </form>ASPX.VB
Imports System Imports System.Collections.Generic Imports System.Configuration Imports System.Data Imports System.Data.Common Imports System.Data.SqlClient Imports System.Web.UI Imports Telerik.Web.UI Public Class bookmarks Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub RadGrid2_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid2.NeedDataSource RadGrid2.DataSource = getBookMarks End Sub Private ReadOnly Property getBookMarks() As IList(Of project) Get Dim strSQL As String = "SELECT PROJ_NAME FROM [OPI_TIMESHEETS] o left outer join DCSC_PROJECT d on o.project_number = d.PROJ_NO " Dim results As IList(Of project) = New List(Of project)() Using connection As IDbConnection = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateConnection() connection.ConnectionString = ConfigurationManager.ConnectionStrings("projcentral").ConnectionString Using command As IDbCommand = connection.CreateCommand() command.CommandText = strSQL connection.Open() Try Dim reader As IDataReader = command.ExecuteReader() While reader.Read() Dim name As String = reader.GetValue(reader.GetOrdinal("PROJ_NAME")) results.Add(New project(name)) End While Catch ex As SqlException results.Clear() 'lblmsg.Text = ex.Message End Try End Using End Using lblMsg.Text = results.Count & " items in list" Return results End Get End Property Class project Private _projName As String Sub New(ByVal name As String) _projName = name End Sub #Region "properties" Private ReadOnly Property Name() As String Get Return _projName End Get End Property #End Region End Class End Class