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
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