I have a simple grid bound to a List of objects.
I have a command button that calls a javascript function which executes an ajax request. In that request I add a new item to the list and rebind my grid. The new item flashes in the grid for a moment then dissappears, leaving only the original item. I am new to telerik but this seem so basic. I must be missing something or not sure how to do this. See code below.
Default.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="bug._Default" %> <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javascript" id="telerikClientEvents1"> function RadButton1_Clicked(sender, args) { $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind"); } </script> </telerik:RadCodeBlock> </head> <body> <form id="form1" runat="server"> <telerik:RadScriptManager ID="RadScriptManager1" runat="server"/> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="grdVoucherTypes" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <table width="600px" style="margin: 0px auto"> <tr><td style="text-align: center"> <telerik:RadButton ID="RadButton1" runat="server" onclientclicked="RadButton1_Clicked" Text="CLick me to add new item" > </telerik:RadButton> </td> </tr> <tr> <td> <telerik:RadGrid ID="grdVoucherTypes" runat="server" AutoGenerateColumns="False" CellSpacing="0" Width="59%" style="margin-top:10px; margin-left: auto; margin-right: auto; margin-bottom: 0px;" AllowPaging="True" AllowSorting="True" GridLines="None" PageSize="20" > <MasterTableView ClientDataKeyNames="VoucherTypeID"> <Columns> <telerik:GridBoundColumn HeaderText="ID" DataField="VoucherTypeID" UniqueName="VoucherTypeID" Visible="False" DataType="System.Int32" ReadOnly="True"/> <telerik:GridBoundColumn HeaderText="Description" DataField="VoucherTypeDesc" UniqueName="VoucherTypeDesc"> <ItemStyle HorizontalAlign="Left"/> <HeaderStyle Width="200px"></HeaderStyle> </telerik:GridBoundColumn> </Columns> </MasterTableView> </telerik:RadGrid> </td> </tr> </table> </form> </body> </html>Default.aspx.vb
Public Class _Default Inherits System.Web.UI.Page Public Property MyList() As List(Of VoucherType) Get Return Session("MyList") End Get Set(value As List(Of VoucherType)) Session("MyList") = value End Set End Property Sub RadAjaxManager1_AjaxRequest(sender As Object, e As Telerik.Web.UI.AjaxRequestEventArgs) Dim x As New VoucherType x.VoucherTypeID = 10 MyList.Add(x) grdVoucherTypes.Rebind() End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim x As New List(Of VoucherType) Dim y = New VoucherType y.VoucherTypeID = 1 x.Add(y) MyList = x 'grdVoucherTypes.DataSource = MyList End Sub Private Sub grdVoucherTypes_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdVoucherTypes.NeedDataSource grdVoucherTypes.DataSource = MyList End Sub End Class Public Class VoucherType Private m_VoucherTypeID As Long Private m_VoucherTypeDescription As String Private m_Value As Long Public IsNew As Boolean Public Property Value As Long Get Return m_Value End Get Set(value As Long) m_Value = value End Set End Property Public Property VoucherTypeID As Long Get Return m_VoucherTypeID End Get Set(value As Long) m_VoucherTypeID = value End Set End Property Public ReadOnly Property Available As Long Get Return 0 End Get End Property Public ReadOnly Property Active As Long Get Return 0 End Get End Property Public ReadOnly Property Expired As Long Get Return Available - Active End Get End Property Public Property VoucherTypeDescription As String Get Return m_VoucherTypeDescription End Get Set(value As String) m_VoucherTypeDescription = value End Set End Property Public ReadOnly Property VoucherTypeDesc As String Get Dim str As String str = Value Return "Test voucher" End Get End Property End Class