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

[Solved] Inserting UserControl not being displayed

5 Answers 240 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 12 Aug 2009, 07:06 PM
I'm trying to use a custom user control for inserting and updating data.  However, when the use clicks the Add new record link the insert user control is not displayed and the grid is left blank.  I think it's because the OnItemCommand event is not firing for some reason.  can someone please help?

Here is some code and markup:

<telerik:RadGrid ID="RadGrid4" runat="server" Skin="WebBlue" Width="95%" 
     AllowPaging="True" AllowSorting="True" 
     OnNeedDataSource="xxxRadGrid1_NeedDataSource" 
     OnUpdateCommand="xxxRadGrid1_UpdateCommand" 
     OnInsertCommand="xxxRadGrid1_InsertCommand" 
     OnDeleteCommand="xxxRadGrid1_DeleteCommand" 
     CommandItemSettings-AddNewRecordText="Add New BMI Measure" 
     OnItemCommand="xxxRadGrid1_ItemCommand" 
    GridLines="Both"
     <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> 
     <MasterTableView DataKeyNames="ID" GridLines="Both" Width="100%" 
         CommandItemDisplay="Top" AutoGenerateColumns="False"
         <Columns> 
          
             <telerik:GridEditCommandColumn> 
             </telerik:GridEditCommandColumn> 
             <telerik:GridBoundColumn DataField="ID" HeaderText="" UniqueName="ID" Visible="false"
             </telerik:GridBoundColumn> 
             <telerik:GridBoundColumn DataField="Height" HeaderText="Height" UniqueName="Height"
             </telerik:GridBoundColumn> 
             <telerik:GridBoundColumn DataField="Weight" HeaderText="Weight" UniqueName="Weight"
             </telerik:GridBoundColumn> 
             <telerik:GridBoundColumn DataField="BMI" HeaderText="BMI" UniqueName="BMI"
             </telerik:GridBoundColumn> 
             <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="Delete" ConfirmDialogType="Classic" ConfirmTitle="Deleting BMI Measure" ConfirmText="Are you sure you want to delete the BMI Measure?">    
           </telerik:GridButtonColumn> 
            
         </Columns> 
     <EditFormSettings EditFormType="WebUserControl" UserControlName="" ColumnNumber="2" CaptionFormatString="Edit details for the Benchmark"   
           CaptionDataField="ID"
           <FormTableItemStyle Wrap="False"></FormTableItemStyle>   
           <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>   
           <FormMainTableStyle CellSpacing="0" CellPadding="3" Width="100%" />   
           <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module"   
               Height="110px" Width="100%" />   
           <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>   
           <FormStyle Width="100%" BackColor="#EEF2EA"></FormStyle>   
           <EditColumn UpdateText="Update BMI Measure" UniqueName="EditCommandColumn1" CancelText="Cancel Edit">    
           </EditColumn>   
           <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>   
        </EditFormSettings> 
        <ExpandCollapseColumn Visible="False">    
           <HeaderStyle Width="19px"></HeaderStyle>   
       </ExpandCollapseColumn>   
       <RowIndicatorColumn Visible="False">   
           <HeaderStyle Width="20px" />   
       </RowIndicatorColumn> 
        
     </MasterTableView> 
 
<FilterMenu Skin="WebBlue" EnableTheming="True"
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</FilterMenu> 
</telerik:RadGrid> 

protected void xxxRadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        RadGrid4.DataSource = bmiMeasures
        RadGrid4.DataMember = "BMIMeasures"
    } 
 
 
protected void xxxRadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if( e.CommandName == RadGrid.InitInsertCommandName ) 
        { 
            e.Canceled = true
            RadGrid4.EditIndexes.Clear(); 
 
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "DesktopModules\\GCCPopulationEncounters\\InsertBMIMeasure.ascx"
            e.Item.OwnerTableView.InsertItem(); 
        } 
        else if( e.CommandName == RadGrid.EditCommandName ) 
        { 
            e.Item.OwnerTableView.IsItemInserted = false
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "DesktopModules\\GCCPopulationEncounters\\EditBMIMeasure.ascx"
        } 
    } 

The Insert, Update, and Delete events are still empty because I haven't gotten that far.  If anyone can take a look and help me out I would greatly appreciate it.

Thank you,
Nick



5 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 14 Aug 2009, 05:30 AM
Hello Nick,

You need to specify the user control name for the edit-form-settings in the Page_Load event.

I hope this helps.

Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nick
Top achievements
Rank 1
answered on 14 Aug 2009, 03:08 PM
I have done this before without having to add anything to the Page_Load event.  Notice in the OnItemCommand event handler, there is code to determine if it's an edit or an insert and sets the user control name appropriately.  I noticed if I change the path to the control to an invalid path it still runs the same as if it never enters the OnItemCommand event handler.  If I do that to my other grid (that is working) it throws an error an says it find the control.

I have one working and one with this problem.  The only difference I can see between the two is that the one that is working is bound to a SqlDataSource while the one that is having the problem is using the OnNeedDataSource event and binding to a DataTable in memory.

Thank you,
Nick
0
Tsvetoslav
Telerik team
answered on 19 Aug 2009, 11:13 AM
Hi Nick,

Did you try my suggestion? Evidently, in your particular case the OnItemCommand event is too late a stage for the user control to be loaded.

Greetings,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Nick
Top achievements
Rank 1
answered on 24 Aug 2009, 02:52 PM
Any idea why the OnItemCommand would be too late a stage?  I would like to avoid setting the control in the Page_Load because I don't have the GridCommandEventArgs, which makes setting the user control very nice and easy.  I can try setting it in the Page_Load.  Do you have or can you point me to an example that does this?  I can't think of a good way to do it in the Page_Load.

Thank you,
Nick
0
Tsvetoslav
Telerik team
answered on 26 Aug 2009, 11:48 AM
Hello Nick,

I am sorry for having failed to properly test your scenario - indeed the OnItemCommand event is an ok-place to assign the name of the user control. However, I could not reproduce the problem. Could you try modifying the attached sample so that the problem is reproduced and get back to us with more information on the issue.

Thank you.

Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Nick
Top achievements
Rank 1
Share this question
or