Can't Bind Grid

3 posts, 0 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 15 Mar 2011 Link to this post

    I'm trying to bind a rad grid from a custom datatable but I cannot get any of the data to show. I have read all your examples but still cannot seem to get it to work. Here's my code
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True"
    GridLines="None" ShowGroupPanel="True" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource">
        <MasterTableView GridLines="None" Width="100%" CommandItemDisplay="Top">
                <telerik:gridboundcolumn datafield="FirstName" headertext="First Name"
                <telerik:gridboundcolumn datafield="LastName" headertext="Last Name"
                <telerik:gridboundcolumn datafield="Business Name" headertext="Business Name"
                <telerik:gridboundcolumn datafield="State" headertext="State"
                <telerik:gridboundcolumn datafield="Zip" headertext="Zip"
                <telerik:gridboundcolumn datafield="Address" headertext="Address"
                <telerik:gridboundcolumn datafield="City" headertext="City"
                <telerik:gridboundcolumn datafield="Phone" headertext="Phone"
                <telerik:gridboundcolumn datafield="Fax" headertext="Fax"
                <telerik:gridboundcolumn datafield="CellPhone" headertext="Cell"
                <telerik:gridboundcolumn datafield="Eamil" headertext="Email"
                <telerik:gridboundcolumn datafield="Edit" headertext="Edit"
        <ClientSettings AllowDragToGroup="True">
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />

    'this function gets the data for the rad grid
    Private Function getData()
        Dim table As DataTable = New DataTable()
        table.Columns.Add("First Name")
        table.Columns.Add("Last Name")
        table.Columns.Add("Business Name")
        'my sql connection
        Dim myConn As New Data.SqlClient.SqlConnection(conn)
        'the name of the stored procedure
        Dim strSQL = "getAllCustomers"
        'add the initial - Please Select -
        'table.Rows.Add(New String() {"-1", "- Please Select -"})
            Dim readCommand As New Data.SqlClient.SqlCommand(strSQL, myConn)
            'while we have rows from the stored procedure
            'we will add them to a data table
            Dim cdr As SqlDataReader = readCommand.ExecuteReader()
            While cdr.Read()
                If (cdr.Item(0).ToString <> "") Then
                    table.Rows.Add(New String() {cdr.Item(1), cdr.Item(2), cdr.Item(3), cdr.Item(4), cdr.Item(5), cdr.Item(6), cdr.Item(7), cdr.Item(8), cdr.Item(9), cdr.Item(10), cdr.Item("<a href='EditCustomer.aspx?id=" & cdr.Item(0) & "'>Edit</a>")})
                End If
            End While 'while cdr.Read()
        Catch ex As Exception
        End Try
        Return table
    End Function 'createTable
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        RadGrid1.DataSource = getData()
    End Sub

  2. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 18 Mar 2011 Link to this post


    I would suggest you to follow the code provided in the following online demo in order to bind the RadGrid correctly.

    Kind regards,
    Maria Ilieva
    the Telerik team

  3. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 18 Mar 2011 Link to this post

    I ended up selecting the data the way I need it in a view, and then using the demo. Thanks,
Back to Top