This is a migrated thread and some comments may be shown as answers.

Binding RadGrind to Business Object Displays Empty Values

1 Answer 42 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Douglas
Top achievements
Rank 1
Douglas asked on 10 Jan 2012, 08:16 PM
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

<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

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Jan 2012, 08:31 AM
Hi,

This is not related to RadGridView for WP - your code is for RadGrid for ASP.NET AJAX.

Please post your question in the relevant forum category!

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Douglas
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or