I am trying to bind a RadGrid to a generic list of business objects using the OnNeedDataSource event. 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 in the list.
.ASPX
ASPX.VB
.ASPX
<formid="form1"runat="server"> <telerik:RadScriptManagerID="RadScriptManager1" runat="server"> </telerik:RadScriptManager> <div> <telerik:RadGridrunat="server"AllowPaging="True"ID="RadGrid2"OnNeedDataSource="RadGrid2_NeedDataSource"Width="600px"PageSize="8"> <MasterTableViewWidth="100%"> <Columns> <telerik:GridBoundColumnHeaderText="Project Name"DataField="name"></telerik:GridBoundColumn> </Columns> <NoRecordsTemplate> <divstyle="height: 30px; cursor: pointer;"> No items to view</div> </NoRecordsTemplate> <PagerStyleMode="NumericPages"PageButtonCount="4"/> </MasterTableView> </telerik:RadGrid> </div> </form> ASPX.VB
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