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

[Solved] User Control updating from the RadGrid

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 16 Oct 2009, 01:29 AM
Hi Support,

I am using a RadGrid with a user control edit form built in.  The RadGrid is ajaxified. 
The problem is when I cancel the insert event with e.Canceled = true the user control is refreshed to its initial settings minus the defaults.  Thus, wiping out the values selected in the dropdown items.  Not only this, but I noticed on a different form with a similar set up that the controls that were programmatically hidden in the user control are shown after the insert event! 

The behavior I would like to see is for the dropdowns to remain populated as they were before the insert is attempted.  The problem is I cannot allow the insert to go forward and must display validation. the validation that I have set up on the insert event indicates that the user has not properly filled in all the fields I set e.canceled = true to stop the grid from going out of edit mode.  Yet, if i attempt to rebind the control the user control refreshes in a way that loses all the data. 

I am pretty perplexed about this issue and don't know what to do to resolve it.  Let me know if there is any other information I can give to help.

Thanks for your help.  See code snippets below. 

Here is my RadGrid definition:
        <asp:Panel ID="pnlRadGrid" runat="server" style="table-layout:fixed" > 
        <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" PageSize="8" 
                AllowSorting="True" AllowPaging="True" AllowMultiRowSelection="False" 
                OnNeedDataSource="RadGrid1_NeedDataSource" 
                OnItemCommand="RadGrid1_ItemCommand"    
                OnInsertCommand="RadGrid1_InsertCommand"   
                OnUpdateCommand="RadGrid1_UpdateCommand" 
                OnItemCreated="RadGrid1_ItemCreated" 
                > 
                <PagerStyle Mode="NextPrevNumericAndAdvanced" HorizontalAlign="Center" /> 
                <MasterTableView EnableTheming="false" InsertItemPageIndexAction="ShowItemOnCurrentPage" InsertItemDisplay="Bottom" DataKeyNames="ProcessingSystemResponseKey" Width="100%" GridLines="None" AllowMultiColumnSorting="True" 
                      CommandItemDisplay="Bottom" TableLayout="Auto" ShowHeadersWhenNoRecords="true">  
                    <Columns> 
                        <telerik:GridTemplateColumn> 
                            <ItemTemplate> 
                                <asp:Button runat="server" CommandName="Edit" CssClass="rgEdit" ToolTip="Edit" /> 
                            </ItemTemplate>   
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn  
                           DataField="ProcessingSystemResponseKey" 
                           HeaderText="Key" 
                           SortExpression="ProcessingSystemResponseKey"   
                           UniqueName="ProcessingSystemResponseKey">  
                         <ItemTemplate> 
                           <href="javascript: void(0)" 
                              onclick="window.open('<%# GetHelpFileUrl(Eval("HelpTopicFile")) %>'); return false;">  
                           <%# Eval("ProcessingSystemResponseKey")%> 
                           </a>     
                        </ItemTemplate> 
                        </telerik:GridTemplateColumn>                           
                        <telerik:GridBoundColumn UniqueName="InpatientResultKindDesc" SortExpression="InpatientResultKindDesc" HeaderText="Inpatient Result" 
                            DataField="InpatientResultKindDesc">  
                        </telerik:GridBoundColumn>                     
                        <telerik:GridBoundColumn UniqueName="OutPatientResultKindDesc" SortExpression="OutPatientResultKindDesc" HeaderText="Outpatient Result" 
                            DataField="OutPatientResultKindDesc">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn UniqueName="Description" SortExpression="Description" 
                            HeaderText="Description" DataField="Description">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridCheckBoxColumn UniqueName="OverrideFlag" SortExpression="OverrideFlag"   
                            HeaderText="Allow MASTRRâ„¢ Agency To Change" DataField="OverrideFlag">  
                        </telerik:GridCheckBoxColumn>                        
                    </Columns> 
                    <EditFormSettings UserControlName="../AdminUC/ManageAdjudicationErrorsUC.ascx" EditFormType="WebUserControl">  
                     </EditFormSettings> 
                <CommandItemSettings AddNewRecordText=""   
                                     RefreshText="" />                       
                </MasterTableView> 
                <ClientSettings AllowKeyboardNavigation="True">    
                    <Selecting AllowRowSelect="False" />    
                </ClientSettings> 
    
        </telerik:RadGrid> 

Here is my Insert Command Eventbelow:
    /// <summary>  
    /// The insert event.  Occurs when user clicks the insert button on the insert form.  
    /// </summary>  
    /// <param name="source"></param>  
    /// <param name="e"></param>  
    protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)  
    {  
        // Obtain the usercontrol from the grid's property  
        UserControl uc = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);  
 
        // Create object to store and validate   
        AdjudicationErrors adjudicationErrors = new AdjudicationErrors();  
          
        // Obtain array to iterate through to determine if inserted primary key is unique.  
        String [] gridKeys = e.Item.OwnerTableView.DataKeyNames;  
 
        // Validate and Assign values   
        if (CheckSetProperFields(uc, adjudicationErrors, gridKeys))  
        {  
            try 
            {  
                // Insert the database record  
                Boolean success = AdjudicationErrors.SaveAdjudicationErrors(adjudicationErrors);  
            }  
            catch (Exception)  
            {  
                e.Canceled = true;  
                throw;  
            }  
 
        }  
        else   
        {  
            e.Canceled = true;  
 
            // Because of the combos the user control doesn't obtain the dropdowns unless the item is   
            // re-obtained  
            GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();  
 
            //Format the grid's insert form  
            SetInsertProperties(insertedItem);  
            insertedItem.OwnerTableView.Rebind();  
 
        } 

Josh

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 21 Oct 2009, 10:59 AM
Hi Josh,

I suggest that you take a look at the Flexible Server-side Validation demo showing how to validate RadGrid. Another option to validate without losing the data and rebinding is performing client-side validation (using javascript).

Please give these suggestions a try and tell me how it goes.

Regards,
Mira
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.
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or