This is a migrated thread and some comments may be shown as answers.

Issue with RadGrid Updation & Insertion.

1 Answer 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
arasu
Top achievements
Rank 1
arasu asked on 28 Mar 2011, 05:20 PM
Hi,
    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>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Mar 2011, 09:30 AM
Hello Arasu,

Give a try with the following code snippet and check whether it works now.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.UpdateCommandName)
       {
            GridEditFormItem editedItem = e.Item as GridEditFormItem;
           string name = (editedItem.FindControl("txtName") as TextBox).Text;
        }
   }

Thanks,
Princy.
Tags
Grid
Asked by
arasu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or