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>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</div> <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server"> </telerik:GridTextBoxColumnEditor> <asp:SqlDataSource ID="salesreps" runat="server" ConnectionString="<%$ ConnectionStrings:cbfSQLConnectionString %>" SelectCommand="SELECT [firstname], [lastname] FROM [salesrep] ORDER BY [termdate], [salesno]"> </asp:SqlDataSource> <telerik:RadListView ID="RadListView1" runat="server" DataSourceID="salesreps" onneeddatasource="RadListView1_NeedDataSource" AllowPaging="True"> <LayoutTemplate> <div class="RadListView RadListView_Forest"> <table cellspacing="0"> <tr> <td ID="itemPlaceholder" runat="server"> </td> </tr> </table> </div> </LayoutTemplate> <ItemTemplate> <td class="rlvI"> <asp:Label ID="firstnameLabel" runat="server" Text='<%# Eval("firstname") %>' /> <br/> <asp:Label ID="lastnameLabel" runat="server" Text='<%# Eval("lastname") %>' /> <br/> </td> </ItemTemplate> <AlternatingItemTemplate> <td class="rlvA"> <asp:Label ID="firstnameLabel" runat="server" Text='<%# Eval("firstname") %>' /> <br/> <asp:Label ID="lastnameLabel" runat="server" Text='<%# Eval("lastname") %>' /> <br/> </td> </AlternatingItemTemplate> <EditItemTemplate> <td class="rlvIEdit"> <table cellspacing="0" class="rlvEditTable"> <tr> <td> <asp:Label ID="firstnameLabel2" runat="server" AssociatedControlID="firstnameTextBox" Text="firstname"> </asp:Label> </td> <td> <asp:TextBox ID="firstnameTextBox" runat="server" CssClass="rlvInput" Text='<%# Bind("firstname") %>' /> </td> </tr> <tr> <td> <asp:Label ID="lastnameLabel2" runat="server" AssociatedControlID="lastnameTextBox" Text="lastname"> </asp:Label> </td> <td> <asp:TextBox ID="lastnameTextBox" runat="server" CssClass="rlvInput" Text='<%# Bind("lastname") %>' /> </td> </tr> </table> </td> </EditItemTemplate> <EmptyDataTemplate> <div class="RadListView RadListView_Forest"> <div class="rlvEmpty"> There are no items to be displayed. </div> </div> </EmptyDataTemplate> <SelectedItemTemplate> <td class="rlvISel"> <asp:Label ID="firstnameLabel" runat="server" Text='<%# Eval("firstname") %>' /> <br/> <asp:Label ID="lastnameLabel" runat="server" Text='<%# Eval("lastname") %>' /> <br/> </td> </SelectedItemTemplate> </telerik:RadListView> <telerik:RadSlider ID="PagerSlider" runat="server" MaximumValue="4" CssClass="slider" DecreaseText="Prev" IncreaseText="Next" DragText='<%# "Page " + (RadListView1.CurrentPageIndex + 1).ToString() + " of 5" %>' AutoPostBack="True" OnValueChanged="PagerSlider_ValueChanged" DbValue="0" Height="22px" Length="200" Width="200px"> </telerik:RadSlider> Dim scriptstring As String = "radalert('Welcome to Rad window!', 550, 250);"ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "radalert", scriptstring, True)function OnGridContextItemClicked(oGridMenu, args) { var menuItemText = args.get_item().get_text(); if (menuItemText == "UnZip") {// 'UnZip' command var oExplorer = $find("<%= rfeStorage.ClientID %>"); var oAjaxPanel = $find("<%= RadAjaxPanel1.ClientID %>"); var selectedItem = oExplorer.get_selectedItem(); if (selectedItem.get_extension() == "zip") { //var itemExt = ; // get the extension of the current item var itemPath = selectedItem.get_path(); // get the path of the current item oAjaxPanel.ajaxRequest(itemPath); // Call the RadAjaxPanel1_AjaxRequest function on the server ; } else { alert("Please, select a ZIP file"); } } } //]]> </script> RadMenuItem item = new RadMenuItem("UnZip"); item.PostBack = false; item.Value = "CustomValue"; rfeStorage.GridContextMenu.Items.Add(item); rfeStorage.GridContextMenu.OnClientItemClicked = "OnGridContextItemClicked";} protected void RadAjaxPanel1_AjaxRequest(object sender, AjaxRequestEventArgs e) { string path = e.Argument; LblAjaxPanel.Text = path; }If
TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
If item("mattach").Text = MailHasAttach Then
Dim img As New System.Web.UI.WebControls.Image
img.ID =
"attachpic"
img.ImageUrl = Session(
"virtualdir") & Session("imagepath") & "attach.gif"
item(
"mattach").Controls.Add(img)
'End If
Else
Dim img As New System.Web.UI.WebControls.Image
img.ID =
"attachpic"
img.ImageUrl = Session(
"virtualdir") & Session("imagepath") & "blank.gif"
item(
"mattach").Controls.Add(img)
End If
<telerik:RadToolTip ID="RadToolTip1" runat="server" TargetControlID="help" IsClientID="true" Animation="Slide"> <asp:Image ID="Image2" runat="server" /> </telerik:RadToolTip>protected void RadComboBox6_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) {
case 1: Image2.ImageUrl = "/App_Themes/img/Mexico-Credencial-del-elector-reverso.jpg";
break;
break; case 2: Image2.ImageUrl = "/App_Themes/img/AGUILA-PJF.JPG"; break; } }