Confused about Grid Items

2 posts, 0 answers
  1. J
    J avatar
    143 posts
    Member since:
    Jun 2006

    Posted 17 Mar 2010 Link to this post

    Is there a resource that explains the difference between GridDataInsertItem, GridDataItem, GridEditableItem, etc...  I'm working with doing the edit form functionality but getting confused who and what I should use when I do either EditMode=InPlace or EditMode=EditForms. 

    For instance if do EditMode=InPlace and have a GridBoundColumn, how do I reference it in an insertCommand?  If its EditMode=EditForms I might do this:
    GridEditFormInsertItem edititem = (GridEditFormInsertItem)e.Item;  
     
    string EquipShortName = ((TextBox)edititem.FindControl("TextBoxName")).Text;  
     

    where 'TextBoxName' is a TextBox control that exists in the FormTemplate on my designer page AND as a GridBoundColumn:
    <MasterTableView CommandItemDisplay="Bottom" EditMode="EditForms">  
        <Columns> 
            <telerik:GridBoundColumn UniqueName="TextBoxName" DataField="TextBoxName">  
            </telerik:GridBoundColumn> 
            <telerik:GridEditCommandColumn   
                UniqueName="EditCommandColumn"   
                CancelText="Cancel" 
                UpdateText="Update"   
                InsertText="Insert"   
                EditText="Edit" 
                > 
            </telerik:GridEditCommandColumn>     
            <telerik:GridButtonColumn CommandName="Delete" Text="Delete"></telerik:GridButtonColumn>                           
        </Columns>    
        <EditFormSettings EditFormType="Template">  
            <FormTemplate> 
                <div style="color:#333333;">  
                    <table width="100%" border="1"   
                    style="  
                        background-color:#D9F0FF;  
                        font-family:Arial;  
                        font-size:9pt;  
                        border-color:Black;  
                        border-left-color:Black;  
                    "  
                    cellpadding="2" cellspacing="2" 
                    > 
                    <tr> 
                        <td style="width:50%">  
                            <table cellpadding="0" cellspacing="0" border="0" width="100%">  
                                <tr> 
                                    <td>Name</td> 
                                    <td align="right</td> 
                                </tr> 
                            </table>                                              
                        </td> 
                        <td style="width:50%">  
                            <asp:TextBox ID="TextBoxName" runat="server" 
                            Text='<%# Bind("TextBoxName") %>'   
                            Width="99%" TextMode="MultiLine" Rows="3" 
                            ></asp:TextBox> 
                        </td> 
                    </tr> 
                </table> 
            </FormTemplate> 
        </EditFormSettings>                                                
    </MasterTableView> 

    But if you do EditMode=InPlace I think I would do the following:
    <MasterTableView CommandItemDisplay="Bottom" EditMode="InPlace">  
        <RowIndicatorColumn> 
            <HeaderStyle Width="120px"></HeaderStyle> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="120px"></HeaderStyle> 
        </ExpandCollapseColumn> 
        <Columns> 
            <telerik:GridBoundColumn DataField="TextBoxName" HeaderText="TextBoxName" UniqueName="TextBoxName">  
            </telerik:GridBoundColumn> 
            <telerik:GridEditCommandColumn   
                UniqueName="EditCommandColumn"   
                CancelText="Cancel" 
                UpdateText="Update"   
                InsertText="Insert"   
                EditText="Edit" > 
            </telerik:GridEditCommandColumn> 
            <telerik:GridButtonColumn CommandName="Delete" Text="Delete"></telerik:GridButtonColumn>   
        </Columns> 
      <EditFormSettings > 
      </EditFormSettings> 
      </MasterTableView> 

    Basically not sure how to get value of TextBoxName when doing InPlace EditMode
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 19 Mar 2010 Link to this post

    Hi Jason,

    The GridEditableItem type is the base class for all grid items that have the capabilities to display and edit data. It is the base class for the GridDataItem and GridDataInsertItem types as well. The GridDataItem type represents a table row of data in the grid. When RadGrid's EditMode is set to EditForms, there is generated another object of type GridEditForm (it has GridEditableItem for its base as well) for each GridDataItem. However, until the GridDataItem enters edit mode this object is set to invisible and hence is not rendered on the client. When the item enters edit mode, the GridEditForm's IsInEditMode property is set to true and the Visible property is switched on. So on the server you can check either for Gthe ridEditForm type or for GridEditableItem type and obligatorily check the IsInEditMode property.
     
    Now, when RadGrid's EditMode is set to InPlace, GridEditForms are not generated for the data items. Instead, when a data item enters edit mode, the GridDataItem object itself is slightly changed so that its table cells no longer contain text but input controls that permit data editing and update/cancel buttons are also added. So you need to work with the GridDataItem object on the server (or again its base class) and check its IsInEditMode property. However, with EditMode=InPlace, you should also check whether the data item has not entered insert mode as when being in insert mode, the data item also has its IsInEditMode property set to true.

    With EditMode=EditForms, when in insert mode the grid generates a GridEditInsertForm item whereas with EditMode=InPlace it generates a GridDataInsertItem. You can work either with those or with their base class which is GridEditableItem again.

    Here is the code for working with the ItemCreated and ItemCommand events with EditMode="InPlace":

    protected void Page_Init(object sender, EventArgs e)
    {
        RadGrid1.ItemCreated += new GridItemEventHandler(RadGrid1_ItemCreated);
        RadGrid1.ItemCommand += new GridCommandEventHandler(RadGrid1_ItemCommand);
    }
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.UpdateCommandName)
        {
            Hashtable updateValues = new Hashtable();
            ((GridEditableItem)e.Item).ExtractValues(updateValues);
        }
        else if (e.CommandName == RadGrid.PerformInsertCommandName)
        {
            Hashtable insertValues = new Hashtable();
            ((GridEditableItem)e.Item).ExtractValues(insertValues);
        }
    }
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem )
        {
            if (!e.Item.OwnerTableView.IsItemInserted)
            {
                //for edit mode
          
            }
            else
            {
                //for insert mode
            }
        }
    }

    I hope this information helps.

    Regards,
    Tsvetoslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top