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

Grid does not refresh.

1 Answer 89 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 22 Jul 2013, 02:50 PM
Hi.
   
     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.

Thanks,
Jian
++++++++++++++++++++++++
Codes for Aspx page

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns='http://www.w3.org/1999/xhtml'>

<head>

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

</head>

<body>

<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:">
                    <Items>
                         <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" />
                    </Items>
               </telerik:RadComboBox>
               
               <telerik:RadButton ID="Button1" runat="server" Text="Get Checked Items" OnClick="Button1_Click" />
   
     </telerik:RadAjaxPanel>
     
     <br /><br />
     <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadGrid ID="RadGrid1" Width="97%" AllowPaging="True" PageSize="15" runat="server"
        AllowSorting="true" GridLines="None">
        <MasterTableView Width="100%">
        </MasterTableView>
        <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
        <FilterMenu EnableTheming="True">
            <CollapseAnimation Duration="200" Type="OutQuint"></CollapseAnimation>
        </FilterMenu>
    </telerik:RadGrid>

</form>

</body>

</html>

=================
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
        conn.Open()
        Try
            adapter.Fill(table1)
        Finally
            conn.Close()
        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)
                Else
                    sb.Append(item.Text + ",")
                End If

                iCnt = iCnt + 1
            Next

        End If

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

    End Sub

End Class
  
    
 
   

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 25 Jul 2013, 07:09 AM
Hi Ron,

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

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:
http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html

Regards,
Eyup
Telerik
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.
Tags
Ajax
Asked by
Ron
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or