Grid does not refresh.

2 posts, 0 answers
  1. Ron
    Ron avatar
    6 posts
    Member since:
    Aug 2008

    Posted 22 Jul 2013 Link to this post

         I have used a Grid, a ComBoBox, and a button to do a simple task.
        User selects something from the ComboBox, then click on the button. I expect the Grid will be refreshed according to the selecttions from the  ComboBox.
        The problem is that the Gird can't be refreshed after the button click, I don't know what is the problem, I have tried RadGrid1.DataBind() and RadGrid1.Rebind().

    Please help.

    Codes for Aspx page

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI"  %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">

    <html xmlns=''>


        <title>Simple Data Binding in AJAX GridView | RadGrid demo</title>



    <form id="form1" runat="server">

        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
         <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1">
                   <telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="false"
                        Width="300" Label="Select SaleRep:">
                             <telerik:RadComboBoxItem Text="6277" />
                             <telerik:RadComboBoxItem Text="6278" />
                             <telerik:RadComboBoxItem Text="6279" />
                             <telerik:RadComboBoxItem Text="6280" />
                             <telerik:RadComboBoxItem Text="6281" />
                             <telerik:RadComboBoxItem Text="6282" />
                             <telerik:RadComboBoxItem Text="6283" />
                             <telerik:RadComboBoxItem Text="6284" />
                             <telerik:RadComboBoxItem Text="6285" />
                             <telerik:RadComboBoxItem Text="6286" />
                             <telerik:RadComboBoxItem Text="6287" />
                             <telerik:RadComboBoxItem Text="6288" />
                   <telerik:RadButton ID="Button1" runat="server" Text="Get Checked Items" OnClick="Button1_Click" />
         <br /><br />
         <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
        <telerik:RadGrid ID="RadGrid1" Width="97%" AllowPaging="True" PageSize="15" runat="server"
            AllowSorting="true" GridLines="None">
            <MasterTableView Width="100%">
            <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
            <FilterMenu EnableTheming="True">
                <CollapseAnimation Duration="200" Type="OutQuint"></CollapseAnimation>




    Code for ASPX.VB Page

    Imports System
    Imports System.Configuration
    Imports System.Data
    Imports System.Data.SqlClient
    Imports Telerik.Web.UI

    Partial Public Class Grid2
        Inherits System.Web.UI.Page

        Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource

            RadGrid1.DataSource = GetDataTable("SELECT TOP 20 [salesRepID],[salesID],[lastName],[firstName] FROM [tpcodata2].[dbo].[salesRep]")

        End Sub

        Public Function GetDataTable(ByVal query As String) As DataTable
            Dim ConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
            Dim conn As SqlConnection = New SqlConnection(ConnString)
            Dim adapter As SqlDataAdapter = New SqlDataAdapter
            adapter.SelectCommand = New SqlCommand(query, conn)
            Dim table1 As New DataTable
            End Try
            Return table1
        End Function

        Public Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
            Dim sb As New StringBuilder()
            Dim collection As IList(Of RadComboBoxItem) = RadComboBox1.CheckedItems
            Dim iCnt As Integer

            If (collection.Count <> 0) Then
                iCnt = 1
                For Each item As RadComboBoxItem In collection
                    If iCnt = collection.Count Then
                        sb.Append(item.Text + ",")
                    End If

                    iCnt = iCnt + 1

            End If

            If sb.ToString() = "" Then
                Me.RadGrid1.DataSource = GetDataTable("SELECT TOP 20 [salesRepID],[salesID],[lastName],[firstName] FROM [tpcodata2].[dbo].[salesRep]")
                Me.RadGrid1.DataSource = GetDataTable("SELECT [salesRepID],[salesID],[lastName],[firstName] FROM [tpcodata2].[dbo].[salesRep] where [salesRepID] in (" + sb.ToString() + ")")
            End If

        End Sub

    End Class
  2. Eyup
    Eyup avatar
    4081 posts

    Posted 25 Jul 2013 Link to this post

    Hi Ron,

    Remove the RadAjaxPanel and add the following setting in the RadAjaxManager's settings:
    <telerik:AjaxSetting AjaxControlID="RadComboBox1">
            <telerik:AjaxUpdatedControl ControlID="RadComboBox1"></telerik:AjaxUpdatedControl>
            <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>

    Furthermore, please note that using DataBind() is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
    Declarative DataSource
    Advanced Data Binding

    Hope this helps. Please make the suggested modification and let me know about the result.

    In addition, you can check out the following topic:

    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top