
<telerik:RadAjaxPanel ID="rjxPanel" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
<asp:UpdatePanel ID="updtPanel" runat="server">
<ContentTemplate>
<telerik:RadButton ID="btnExport" runat="server" OnClick="btnExport_Click" Text="Export" />
<telerik:RadGrid ID="rgCostAllocation" runat="server" OnNeedDataSource="rgCostAllocation_NeedDataSource"
OnItemDataBound="rgCostAllocation_ItemDataBound" OnDeleteCommand="rgCostAllocation_DeleteCommand"
ShowFooter="true">
<ExportSettings Excel-Format="ExcelML" ExportOnlyData="true" IgnorePaging="true" HideStructureColumns="true"></ExportSettings>
<MasterTableView CommandItemDisplay="Top">
<CommandItemSettings ExportToExcelText="Export" ShowExportToExcelButton="true" />
<Columns>
<telerik:GridBoundColumn DataField="CostAllocationId" HeaderText="CostAllocationId"
UniqueName="CostAllocationId" Display="false">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="AllocationLevel" HeaderText="Level" UniqueName="AllocationLevel"
AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo" Display="false">
<ItemTemplate>
<telerik:RadNumericTextBox ID="txtLevel" runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.AllocationLevel") %>'
NumberFormat-AllowRounding="false" NumberFormat-DecimalDigits="0" />
</ItemTemplate>
<FooterTemplate>
<telerik:RadNumericTextBox ID="txtFLevel" runat="server" NumberFormat-AllowRounding="false"
NumberFormat-DecimalDigits="0" />
</FooterTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="SenderDescription" HeaderText="Sender" UniqueName="SenderCostCenterId" AllowFiltering="true"
AutoPostBackOnFilter="true" CurrentFilterFunction="Contains">
<ItemTemplate>
<telerik:RadComboBox ID="rcbSender" runat="server"
MarkFirstMatch="True" AutoPostBack="true"
Width="170px" OnItemsRequested ="rcbSender_ItemsRequested"
height="200px" EnableLoadOnDemand="True"
ItemRequestTimeout ="500" DropDownWidth="280px"
DataTextField="CostCentreDescription"
DataValueField="CostCentreID" ExpandEffect="pixelate">
<headertemplate>
<table width="92%">
<tr>
<td style="font-weight:bold; width:50%;"> Cost Centre Description</td>
<td style="font-weight:bold; width:50%;">Cost Centre Code</td>
</tr>
</table>
</headertemplate>
<itemtemplate>
<table width="100%">
<tr>
<td style="width: 50%; font-size: 8pt; font-family: Arial;" align="left">
<%# DataBinder.Eval(Container, "Attributes['DataValue']") %>
</td>
<td align="left" style="font-size: 8pt; width: 50%; font-family: Arial;">
<%# DataBinder.Eval(Container, "Attributes['DataText']")%>
</td>
</tr>
</table>
</itemtemplate>
</telerik:RadComboBox>
</ItemTemplate>
<FooterTemplate>
<telerik:RadComboBox ID="rcbFSender" runat="server"
MarkFirstMatch="True" AutoPostBack="true"
Width="170px" OnItemsRequested ="rcbFSender_ItemsRequested"
height="200px" EnableLoadOnDemand="True" ItemRequestTimeout ="500"
DataTextField="CostCentreDescription"
DataValueField="CostCentreID"
DropDownWidth="280px"
ExpandEffect="pixelate" >
<headertemplate>
<table width="92%">
<tr>
<td style="font-weight:bold; width:50%;"> Cost Centre Description</td>
<td style="font-weight:bold; width:50%;">Cost Centre Code</td>
</tr>
</table>
</headertemplate>
<itemtemplate>
<table width="100%">
<tr>
<td style="width: 50%; font-size: 8pt; font-family: Arial;" align="left">
<%# DataBinder.Eval(Container, "Attributes['DataValue']") %>
</td>
<td align="left" style="font-size: 8pt; width: 50%; font-family: Arial;">
<%# DataBinder.Eval(Container, "Attributes['DataText']")%>
</td>
</tr>
</tr>
</table>
</itemtemplate>
</telerik:RadComboBox>
</FooterTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="AllocationPercentage" HeaderText="Percentage"
UniqueName="AllocationPercentage" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains">
<ItemTemplate>
<telerik:RadNumericTextBox Width="60px" ID="txtPercentage" runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.AllocationPercentage") %>'
Type="Percent" />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSumPercentage" runat="server" />
<telerik:RadNumericTextBox Width="60px" ID="txtFPercentage" runat="server" Type="Percent" />
<telerik:RadButton ID="btnAddNew" runat="server" OnClick="btnAddNew_Click" Text="Add New" />
</FooterTemplate>
<ItemStyle Width="15%" />
</telerik:GridTemplateColumn>
<telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" UniqueName="DeleteCommandColumn"
HeaderText="Delete" ConfirmText="Are you sure you want to delete?" Text="Delete">
<ItemStyle HorizontalAlign="Center" Width="3%" />
<HeaderStyle HorizontalAlign="Center" Width="3%" />
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</ContentTemplate>
</asp:UpdatePanel>
</telerik:RadAjaxPanel>
protected void btnExport_Click(object sender, EventArgs e)
{
try
{
rgCostAllocation.MasterTableView.ExportToExcel();
}
catch (Exception ex)
{
XITingExceptionProcessor.ProcessException(this, ex);
}
}
I have the following markup on my aspx page:
<telerik:RadAjaxManagerProxy runat="server" ID="MyAjaxManagerProxy"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="MyRadGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="MyRadGrid1" LoadingPanelID="AjaxLoadingPanel1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManagerProxy> <telerik:RadAjaxLoadingPanel ID="AjaxLoadingPanel1" runat="server" Transparency="20"> <telerik:RadCodeBlock ID="VpLaborHourlyRadCodeBlock1" runat="server"> <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border: 0;" /> </telerik:RadCodeBlock> </telerik:RadAjaxLoadingPanel>
My radgrid declaration immediately follows.
I have a delete button in each row of my radgrid. The delete event handler is implemented in ItemCommand as so:
protected void MyRadGrid_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
// Save the row into database.
}
else if (e.CommandName == RadGrid.DeleteCommandName)
{
// Delete the row from the database.
}
}
The delete function works fine, that is, the row does get deleted from the database. There is only one problem as described below.
The first time I delete a row, ajax works perfectly, no full postback, the grid stays where it is and get rebound nicely after delete completes.
The second time I delete a row, it still successfully deletes the row from the database, but it does a full postback, and the entire page reloads, totally without the nice ajax feature.
What's wrong? Any hint please?
| <table cellspacing="0" cellpadding="0" width="95%" style="text-align:right" border="1"> |
| <tr> |
| <td style="width:auto"></td> |
| <td> |
| <telerik:RadMenu ID="mnuRootTop" runat="server" DataSourceID="sitemapWto" Skin="WtoRootTop" |
| EnableEmbeddedSkins="false" /> |
| <asp:SiteMapDataSource ID="sitemapWto" runat="server" SiteMapProvider="wtoTopMenu" /> |
| </td> |
| <td> |
| <img alt="" src="../Images/separator.gif" /> |
| </td> |
| <td> |
| <telerik:RadMenu ID="mnuNewsTop" runat="server" DataSourceID="sitemapNews" Skin="WtoNewsTop" |
| EnableEmbeddedSkins="false" EnableAutoScroll="true" /> |
| <asp:SiteMapDataSource ID="sitemapNews" runat="server" SiteMapProvider="newsTopMenu" /> |
| </td> |
| <td> |
| <img alt="" src="../Images/separator.gif" /> |
| </td> |
| <td> |
| <telerik:RadMenu ID="mnuTradeTop" runat="server" DataSourceID="sitemapTrade" Skin="WtoTradeTop" |
| EnableEmbeddedSkins="false" /> |
| <asp:SiteMapDataSource ID="sitemapTrade" runat="server" SiteMapProvider="tradeTopMenu" /> |
| </td> |
| <td> |
| <img alt="" src="../Images/separator.gif" /> |
| </td> |
| <td> |
| <telerik:RadMenu ID="mnuRessTop" runat="server" DataSourceID="sitemapRess" Skin="WtoRessTop" |
| EnableEmbeddedSkins="false" /> |
| <asp:SiteMapDataSource ID="sitemapRess" runat="server" SiteMapProvider="ressTopMenu" /> |
| </td> |
| <td> |
| <img alt="" src="../Images/separator.gif" /> |
| </td> |
| <td> |
| <telerik:RadMenu ID="mnuDocsTop" runat="server" DataSourceID="sitemapDocs" Skin="WtoDocsTop" |
| EnableEmbeddedSkins="false" /> |
| <asp:SiteMapDataSource ID="sitemapDocs" runat="server" SiteMapProvider="docsTopMenu" /> |
| </td> |
| <td> |
| <img alt="" src="../Images/separator.gif" /> |
| </td> |
| <td> |
| <telerik:RadMenu ID="mnuForumsTop" runat="server" DataSourceID="sitemapForum" Skin="WtoForumsTop" |
| EnableEmbeddedSkins="false" /> |
| <asp:SiteMapDataSource ID="sitemapForum" runat="server" SiteMapProvider="forumTopMenu" /> |
| </td> |
| </tr> |
| </table> |
public static string outputDate(this Telerik.Web.UI.RadDateTimePicker radPicker, string formatter) { if (radPicker.IsEmpty || radPicker.SelectedDate == null) { return String.Empty; } switch (formatter.ToLower()) { case "text": case "date": return radPicker.SelectedDate.Value.ToShortDateString(); case "value": case "datetime": return radPicker.SelectedDate.Value.ToString(); default: try {return radPicker.SelectedDate.Value.ToString(formatter); } catch {return String.Empty; } } }manager = RadAjaxManager.GetCurrent(Page);manager.AjaxSettings.AddAjaxSetting(this.pnlTop, this.pnlTop, this.RadAjaxLoadingPanel1);manager.AjaxRequest += this.ajaxManager_AjaxRequest;