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

The Grid failed to refrehsh

2 Answers 23 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 22 Jul 2013, 05:56 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

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Jul 2013, 07:04 AM
Hello,

Please try with the below code snippet.

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
       <AjaxSettings>
           <telerik:AjaxSetting AjaxControlID="Button1">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
               </UpdatedControls>
           </telerik:AjaxSetting>
           <telerik:AjaxSetting AjaxControlID="RadGrid1">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
               </UpdatedControls>
           </telerik:AjaxSetting>
       </AjaxSettings>
   </telerik:RadAjaxManager>


Thanks,
Jayesh Goyani
0
Ron
Top achievements
Rank 1
answered on 23 Jul 2013, 12:21 PM
Jayesh:

   Thank you so much.

   The problem is fixed now.

Jian
Tags
Grid
Asked by
Ron
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Ron
Top achievements
Rank 1
Share this question
or