I am facing issue with updating the radgrid using PopUp edit FormTemplate.
- I have used NHibernate datasource<(IList<>) to bind the Radgrid.
- I have used formtemplate in radgrid to update or insert using radcontext menu.
DataSource=
IQuery query = session.GetNamedQuery("sp_Sample");
IList<Sample>result = query.List<
Sample>();
How do i get the updated values from the PopUp screen in RadGrid1_ItemCommand()
- when i am clicking the update button in the popup screen RadGrid1_ItemCommand() method
is firing but it has only old values. - if i will get the updated values, then it will be helpful to update() the database.
- Please help in this.
I have used below code to get the updated values but it is not working.
if (e.CommandName == RadGrid.UpdateCommandName)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
Hashtable
newValues = new Hashtable();
newValues[
"Name"] = (editedItem.FindControl("txtName") as TextBox).Text;
newValues[
"Address1"] = (editedItem.FindControl("txtAddress1") as TextBox).Text;
newValues[
"Address2"] = (editedItem.FindControl("txtAddress2") as TextBox).Text;
newValues[
"Address3"] = (editedItem.FindControl("txtAddress3") as TextBox).Text;
newValues[
"PhoneNumber"] = (editedItem.FindControl("txtPhoneNumber") as TextBox).Text;
}
RadGrid.aspx Code:
<
telerik:RadPanelBar ID="RadPanelBar2" runat="server" OnClientItemCollapse="OnClientItemCollapsed" Skin="Telerik" Width="100%" >
<Items >
<telerik:RadPanelItem Text="RadGrid With Data" runat="server">
<Items>
<telerik:RadPanelItem runat="server" />
</Items>
<ItemTemplate>
<!-- Empty template to suppress global template -->
</ItemTemplate>
</telerik:RadPanelItem>
</Items >
<ItemTemplate>
<div class="module" style="width:100%;float:left">
<br />
<
asp:Panel ID="GridViewPanel1" runat="server">
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
AllowPaging="True" AllowSorting="True" GridLines="None"
ShowGroupPanel="True" Skin="Hay" AllowAutomaticUpdates="true" OnItemCommand="RadGrid1_ItemCommand" >
<MasterTableView EditMode="PopUp" >
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"><HeaderStyle Width="20px"></HeaderStyle></RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"><HeaderStyle Width="20px"></HeaderStyle></ExpandCollapseColumn>
<EditFormSettings EditFormType="AutoGenerated" >
<FormTemplate>
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Name:
</td>
<td>
<asp:TextBox ID="txtName" Text='<%# Bind( "Name") %>' runat="server">
</asp:TextBox>
</td>
</tr>
<tr>
<td>
Number:
</td>
<td>
<asp:TextBox ID="txtClientNumber" Text='<%# Bind( "Number") %>' runat="server">
</asp:TextBox>
</td>
</tr>
<tr>
<td>
Address1:
</td>
<td>
<asp:TextBox ID="txtAddress1" Text='<%# Bind( "Address1") %>' runat="server">
</asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>
Address2:
</td>
<td>
<asp:TextBox ID="txtAddress2" runat="server" Text='<%# Bind( "Address2" ) %>'>
</asp:TextBox>
</td>
</tr>
<tr>
<td>
Address3:
</td>
<td>
<asp:TextBox ID="txtAddress3" runat="server" Text='<%# Bind( "Address3") %>'>
</asp:TextBox>
</td>
</tr>
<tr>
<td>
PhoneNumber:
</td>
<td>
<asp:TextBox ID="txtPhoneNumber" runat="server" Text='<%# Bind( "PhoneNumber") %>'>
</asp:TextBox>
</td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td align="right" colspan="2">
<asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' OnClick="Button1_Click">
</asp:Button>
<asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" Visible="false" />
</Columns>
<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column"></EditColumn>
</EditFormSettings>
</MasterTableView>
<ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True" ReorderColumnsOnClient="True">
<ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>
<Selecting AllowRowSelect="true" />
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<%
--<FilterMenu EnableImageSprites="False"></FilterMenu>--%>
<
HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
</
telerik:RadGrid>
</asp:Panel>
<telerik:RadContextMenu ID="RadMenu1" runat="server" OnItemClick="RadMenu1_ItemClick" EnableRoundedCorners="true" EnableShadows="true">
<Items>
<telerik:RadMenuItem Text="Add" />
<telerik:RadMenuItem Text="Edit" />
<telerik:RadMenuItem Text="Delete" />
</Items>
</telerik:RadContextMenu>
</div>
</ItemTemplate>
</
telerik:RadPanelBar>