FindControl in InsertItem of RadGrid with FormTemplate(EditForm Template)

3 posts, 0 answers
  1. siva sankaran
    siva sankaran avatar
    2 posts
    Member since:
    Nov 2016

    Posted 08 Nov Link to this post

    <p><telerik:RadGrid ID="SampleGrid"  GridLines="None" runat="server" AllowAutomaticDeletes="false"<br>                              AllowPaging="True" PageSize="10" AllowAutomaticInserts="false" AllowAutomaticUpdates="false"<br>                              AutoGenerateColumns="False" MasterTableView-EditMode="EditForms" ShowFooter="false"<br>                              MasterTableView-CommandItemSettings-ShowRefreshButton="false"<br>                              OnNeedDataSource="SampleGrid_NeedDataSource" OnInsertCommand="SampleGrid_InsertCommand"<br>                              OnItemCommand="SampleGrid_ItemCommand" OnUpdateCommand="SampleGrid_UpdateCommand" OnItemDataBound="SampleGrid_ItemDataBound"<br>                              Width="100%"><br>                              <PagerStyle Mode="NextPrevAndNumeric" /><br>                              <MasterTableView Width="100%" CommandItemDisplay="Top" HorizontalAlign="NotSet" AutoGenerateColumns="False"<br>                                  DataKeyNames="ID" Caption="Sample" ><br>                                  <Columns></p><p><telerik:GridTemplateColumn HeaderText="Action" AllowFiltering="false"><br>                                          <ItemTemplate><br>                                              <asp:ImageButton ID="ImgBtnEdit" runat="server" CommandName="Edit" CausesValidation="False"<br>                                                  ImageUrl="../Images/icons/page-edit.png" ToolTip="Edit" ImageAlign="AbsMiddle"><br>                                              </asp:ImageButton><br>                                          </ItemTemplate><br>                                          </telerik:GridTemplateColumn></p><p>  <telerik:GridBoundColumn DataField="NAME" HeaderText="Name" UniqueName="NAME"<br>                                          ItemStyle-Width="120px"><br>                                      </telerik:GridBoundColumn></p><p>  </Columns><br>                                  <EditFormSettings EditFormType="Template"><br>                                      <FormTemplate></p><p><table class="detailtable" cellspacing="2" cellpadding="1" width="100%" border="0"<br>                rules="none" style="border-collapse: collapse;"><br>                <tr><br>                    <td class="detaillabel"><br>                        Brand:<br>                    </td><br>                    <td><br>                         <telerik:RadComboBox ID="Name" runat="server" Width="250px"   AllowCustomText="true" EmptyMessage="Select" EnabledStyle-HorizontalAlign="Right"><br>                                                       </telerik:RadComboBox><br>                    </td><br>                </tr><br>            </table><br>        </div><br>    </FormTemplate><br></EditFormSettings></p>  </MasterTableView><br>                              <GroupingSettings CaseSensitive="false" ShowUnGroupButton="true" /><br>                              <ClientSettings EnableRowHoverStyle="true" AllowDragToGroup="true" ReorderColumnsOnClient="true"<br>                                  AllowGroupExpandCollapse="true" AllowColumnsReorder="true"><br>                                  <Selecting AllowRowSelect="True" EnableDragToSelectRows="true" /><br>                              </ClientSettings><br><br>                          </telerik:RadGrid><br>

     

    I want to find the ComboBox and bind combo box with some values so that While inserting record , the end user can choose a value to insert or save

    <p style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;"></code></span></span></p><p style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;"> protected void SumInsGrid_ItemDataBound(object sender, GridItemEventArgs e)<br>        {<br><br>            GridDataItem dataItem = e.Item as GridDataItem;<br><br>            if (e.Item is GridEditFormInsertItem)<br>            {<br>                RadComboBox Name = (RadComboBox)e.Item.FindControl("Name");<br>                BindComboBox(Name);<br>            }</code></span></span></p><p style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;">            else if (e.Item is GridEditFormItem && e.Item.IsInEditMode)<br>            {</code></span></span></p><p style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;">                     ...........</code></span></span></p><p style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;">                     RadComboBox Name = (RadComboBox)e.Item.FindControl("Name");<br style="color: rgb(0, 0, 0); font-family: monospace;">                     BindComboBox(Name);</code></span></span></p><p style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;">                     ...</code></span></span></p><p style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;">            }</code></span></span></p><p style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;">    }</code></span></span></p><p style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;"></code></span></span></p>

     

    While Editing findControl method works by returning the ComboBox object but not While Inserting. I want to bind values programmatically to the RadComboBox. 

  2. siva sankaran
    siva sankaran avatar
    2 posts
    Member since:
    Nov 2016

    Posted 08 Nov Link to this post

    Sorry., Formatting is a mess

    aspx code is here http://pastebin.com/uTxsvuqF

    Code behind is here http://pastebin.com/4nKAC61M

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 11 Nov Link to this post

    Hello Siva,

    The most straightforward way of achieving combo editing is placing a combo control inside the EditItemTemplate of GridTemplateColumn or FormTemplate:
    http://demos.telerik.com/aspnet-ajax/grid/examples/columns-rows/columns/column-types/defaultcs.aspx


    And make avail of the SelectedValue property and the Bind expression:
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx

    https://msdn.microsoft.com/en-us/library/vstudio/ms178366%28v=vs.100%29.aspx


    Alternatively, you can use GridDropDownColumn:
    http://demos.telerik.com/aspnet-ajax/grid/examples/columns-rows/columns/column-types/defaultcs.aspx
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/columns/column-types#griddropdowncolumn

    The GridDropDownColumn generates a combo control only during insert or edit mode:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/customize-griddropdowncolumn

    Therefore, you can access it only during these modes:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-controls-in-editinsert-mode

    If you use GridTemplateColumn approach, you can also bind the combo using its DataBinding event handler:
    http://www.telerik.com/forums/grid-filter-contains-not-finding-anything#ZhplbQLMI0iOiGnkWdM0OQ

    I hope this will prove helpful.

    Regards,
    Eyup
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top