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

[Solved] Can't Get Edit Form to work

7 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 07 Sep 2009, 11:17 AM
Hi,

I have a grid with auto-generated columns.  The grid is filled during run time (via a SQL query). 

I try to use Edit Form for Update/Insert.  The grid renders correctly...the Edit Form opens correctly when I click either the Update link or the Add New Record link.

I use the RadGrid1_UpdateCommand to process the update event.  I try to extract the changed value from the textbox in the edit form, but the textbox.text returns the old value and not the new value.  Hence I cannot process the update.  Same is true with the insert.

I spent hours checking postings and demo materials and couldn't find the answer.  Very frustrating and time-consuming.  Just about ready to abandon this but thought I should give me one last shot and hopefully someone will be able to offer some advise.

Below are the code snippets.  Any comments or advise will be greatly appreciated.

Thanks.

Barry
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="EditDepartment.aspx.vb" Inherits="EditDepartment" title="Untitled Page" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">  
    &nbsp;  
      
     <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
         <AjaxSettings> 
             <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                 <UpdatedControls> 
                     <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                 </UpdatedControls> 
             </telerik:AjaxSetting> 
         </AjaxSettings> 
     </telerik:RadAjaxManager> 
          
    <asp:Panel ID="Panel2" runat="server" BorderColor="Silver" BorderStyle="solid" BorderWidth="1px" 
        Height="200px" Style="z-index: 101; left: 4px; position: relative; top: 0px" 
        Width="95%">  
        <telerik:RadTextBox ID="radTextBox2" runat="server" Style="z-index: 101; left: 1px;  
            position: absolute; top: 6px" Text="abc" Width="100px">  
        </telerik:RadTextBox> 
        <telerik:RadGrid ID="RadGrid1" runat="server"   
            GridLines="None" AutoGenerateColumns="True" AutoGenerateEditColumn = "true"   
            Skin="Office2007" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"   
            AllowAutomaticUpdates="true" ShowFooter="True" > 
           <MasterTableView CommandItemDisplay="Bottom">  
               <EditFormSettings> 
                   <EditColumn UniqueName="EditCommandColumn1">  
                   </EditColumn> 
               </EditFormSettings> 
            </MasterTableView> 
            <ClientSettings EnablePostBackOnRowClick="True">  
            </ClientSettings> 
        </telerik:RadGrid></asp:Panel> 
          
</asp:Content> 
 

 
    Protected Sub RadGrid1_UpdateCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand  
 
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)  
 
        Dim textbox As TextBox  
        textbox = CType(editedItem("description").Controls(0), TextBox)  
 
    End Sub 

7 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 07 Sep 2009, 11:48 AM
Hello Barry,

Please examine the following forum threads and let me know if they help to achieve wanted behavior.
New value for cell in edit mode
Textbox Value in EditForm

All the best,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Shinu
Top achievements
Rank 2
answered on 07 Sep 2009, 12:18 PM
Hi Barry,

You may also check whether you have disabled the ViewState of the grid by any chance in code behind. If so, you would have to enable  ViewState for the control to retrieve updated values on postback.

Shinu
0
Barry
Top achievements
Rank 1
answered on 07 Sep 2009, 08:04 PM
Hi Pavlina and Shinu,

First of all, thanks for responding to my post so quickly.  Reponse to your comments/advise:

1. Pavlina, I looked through the links you provided.  I'm actually following one of the approaches (the most logical one) from the link, i.e. I'm using the Radgrid1_UpdateCommand event to extract the edited value...identical to what's shown in the link.  But to no avail.  The only difference I see between my project and what's shown in the link is I'm auto-generating the grid during run time.

2, Shinu, the viewState is enabled in the grid and there is no code-behind to turn that off.

After spending some more time on this, I did find a new lead:

It appears that when I click the "update" command (auto-generated) inside the Edit Form (after I've entered a new value in one of the textboxes), a postback event is fired BEFORE the radgrid1_UpdateCommand event.  My code "refreshes" the grid at the postback event; therefore, it is essentially wiping out the editd values.  (I was able to confirm this by "artificially" bypassing the grid refresh before the UpdateCommand event).

Then it occurs to me that I need to move the grid refresh out of the PostBack event to the following events instead: EditCommand, UpdateCommand, InsertCommand and CancelCommand instead.  After doing that, i was able to extract the new values in the UpdateCommand event.  Now the new issues are:

1.  I refresh the grid after the UpdateCommand handling.  However, when the page renders, it doesn't close the Edit Form even though the user has clicked the Update link.

2.  When user clicks the "Add New Record" link, the grid renders empty because the grid did not refresh.  Is there a server event triggered by the click of the "Add New Record" link?

.Thanks for your help.

Thanks.

Barry
0
Shinu
Top achievements
Rank 2
answered on 08 Sep 2009, 05:16 AM
Hi Barry,

1) If you are performing manual Insert/Update/Delete operations try setting the AllowAutomaticDeletes/ AllowAutomaticInserts/    AllowAutomaticUpdates to false and see whether the edit form is getting closed when you click the Update button.

2) The ItemCommand event will be fired when you click the AddNewRecord button.

 CS:
 
protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "InitInsert"
        {  
         
        } 
 
    } 


Thanks
Shinu
0
Barry
Top achievements
Rank 1
answered on 08 Sep 2009, 08:10 AM
Shinu,

There's a reason why you're a MVP.  Your answers to my questions hit the spot exactly.  Everything works as expected now. Thank you so much!  Final question if you don't mind:

When user clicks the Edit button, the Edit Form opens up.  I would like to add a couple of radListBoxes to the Edit Form so user can supply additional info.  I am able to add these listboxes in code with no problem during the ItemDataBound event.  But the listboxes show up sort of in an odd spot.  My question is: can I reposition these listboxes and add labels to them, etc. so that asthetically the Edit Form looks right. 

Is there a better approach?

Thanks again.

Barry
0
Shinu
Top achievements
Rank 2
answered on 08 Sep 2009, 08:48 AM
Hi Barry,

I would suggest you to use a FormTemplate/UserControl edit form so that you can customize the edit form according to your needs rather than modifying the autogenerated edit form in code behind. You may go through the following online demos for getting more details about using FormTemplate/UserControl edit form.
Form Template Edit Form
User Control Edit Form


Thanks
Shinu.
0
Barry
Top achievements
Rank 1
answered on 09 Sep 2009, 12:40 AM
Shinu,

Thanks for your help.  Indeed, I looked into customer edit form and user control edit form; they both look promising.

Barry
Tags
Grid
Asked by
Barry
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Shinu
Top achievements
Rank 2
Barry
Top achievements
Rank 1
Share this question
or