Insert Record using UserControl

6 posts, 0 answers
  1. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 21 Oct 2009 Link to this post

    I'm trying to figure out how to insert a record by using a UserControl. I have a Master Gridview with a child gridview and want to be able to insert a new record into the child grid. I have created a UserControl  "InsertOil.ascx" and added a reference to it in the RadGrid but when I click on the Add New Record button I only get the built in edit/insert form which works so I guess I have not configured the grid to call the UserControl properly. I will post the relevant code in hopes that someone can stewer me in the right directio before I go completely mad. Thanks for any help.          




    <%@ Page Title="" Language="VB" MasterPageFile="~/Facilities.master" AutoEventWireup="false" CodeFile="OilAdditions.aspx.vb" Inherits="SiteReporting_OilAdditions" %>  
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>  
     
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">  
     
    <telerik:RadGrid ID="RadGrid1"   
                     runat="server"   
                     DataSourceID="sdsGenerators"   
                     GridLines="None"   
                     ShowGroupPanel="True" Skin="Hay"   
                     AutoGenerateColumns="False" 
                     Width="500px">  
     
    <MasterTableView DataSourceID="sdsGenerators"   
                     GroupLoadMode="Client"   
                     DataKeyNames="EquipmentID"   
                     HierarchyLoadMode="Client" 
                       
                       
                       
                     >  
     
     
        <DetailTables>  
            <telerik:GridTableView  runat="server"   
                                    DataSourceID="sdsOilAdditions"   
                                    AllowAutomaticInserts="True"   
                                    GroupLoadMode="Client"   
                                    HierarchyLoadMode="Client" AllowPaging="True"   
                                    CommandItemDisplay="Top">  
                <ParentTableRelation>  
                    <telerik:GridRelationFields  DetailKeyField="EquipmentID"   
                                                 MasterKeyField="EquipmentID" />  
                </ParentTableRelation>  
                  
                <Columns>  
                    <telerik:GridBoundColumn DataField="DateAdded" DataFormatString="{0:dd MMM,  yy}" HeaderText="DateAdded" DataType="System.DateTime" UniqueName="DateAdded">  
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="Quantity" HeaderText="Qty (Gals)" DataType="System.Double" UniqueName="Quantity">  
                    </telerik:GridBoundColumn>  
                    <telerik:GridBoundColumn DataField="Scheduled" HeaderText="Added During RWP" DataType="System.Boolean" UniqueName="Scheduled">  
                    </telerik:GridBoundColumn>  
                      
     
     
                     
                </Columns>  
                  
            </telerik:GridTableView>  
        </DetailTables>  
                    
    <ExpandCollapseColumn Visible="True"></ExpandCollapseColumn>  
                    
                <Columns>  
                    <telerik:GridBoundColumn DataField="EquipmentID_Old"   
                                             HeaderText="Generator"   
                                             SortExpression="EquipmentID_Old"   
                                             UniqueName="EquipmentID_Old">  
                    </telerik:GridBoundColumn>  
                </Columns>  
                <EditFormSettings UserControlName="InsertOil.ascx" EditFormType="WebUserControl">  
                        <EditColumn UniqueName="EditCommandColumn1">  
                        </EditColumn>  
                    </EditFormSettings>  
         </MasterTableView>  
             
        </telerik:RadGrid>  
           
        <asp:SqlDataSource ID="sdsGenerators" runat="server"   
            ConnectionString="<%$ ConnectionStrings:AAIOMSConnectionString %>"   
            SelectCommand="spSelectFAC_PowerPlantsBySiteID"   
            SelectCommandType="StoredProcedure">  
            <SelectParameters>  
                <asp:SessionParameter DefaultValue="7" Name="SiteID" SessionField="SiteID"   
                    Type="Int32" />  
            </SelectParameters>  
        </asp:SqlDataSource>  
         
        <asp:SqlDataSource ID="sdsOilAdditions" runat="server"   
            ConnectionString="<%$ ConnectionStrings:AAIOMSConnectionString %>"   
            SelectCommand="spSelectFAC_OilAdditionsByEquipmentID"   
            SelectCommandType="StoredProcedure"   
            InsertCommand="spInsertFAC_OilAdditions" InsertCommandType="StoredProcedure">  
            <SelectParameters>  
                <asp:SessionParameter Name="EquipmentID"  SessionField="EquipmentID"   
                    Type="Int32" />  
            </SelectParameters>  
            <InsertParameters>  
                <asp:Parameter Name="EquipmentID"  Type="Int32" />  
                <asp:Parameter Name="DateAdded" Type="DateTime" />  
                <asp:Parameter Name="Scheduled" Type="Boolean" />  
                <asp:Parameter Name="Quantity" Type="Double" />  
                <asp:Parameter Name="AddedBy" Type="String" />  
            </InsertParameters>  
        </asp:SqlDataSource>  
    </asp:Content>  
     

    Here is the User Control 
     
    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="InsertOil.ascx.vb" Inherits="WorkOrders_InsertOil" %>  
     
            EquipmentID<asp:TextBox ID="txtEquipmentID" runat="server"></asp:TextBox><br />  
            Date Added<asp:TextBox ID="txtDateAdded" runat="server"></asp:TextBox><br />  
            Quantity<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox><br />  
            Added By<asp:TextBox ID="txtAddedBy" runat="server"></asp:TextBox><br />  
            Scheduled<asp:CheckBox ID="chkScheduled" runat="server" /> 


  2. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 21 Oct 2009 Link to this post

    OK I am getting somewhere but still not all the way there. I have figured out that I needed to add some attributes to the GridTableView to get the UserControl to pop up when the Add new record button is clicked. I added 
    EditFormSettings-EditFormType="WebUserControl"                 
    EditFormSettings-UserControlName="InsertOil.ascx" 
    OK so now that I have my custom UserControl working  I just need to be able to pass the DataKeyField to it.  

     

     

     

     

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 22 Oct 2009 Link to this post

    Hello AkAlan,

    How to updat/insert grid records or pass key field values using WebUserControl custom edit form you can see from the following resources on our site:

    http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx

    http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesusercontrolformtemplate.html
    http://www.telerik.com/help/aspnet-ajax/grdupdatingvaluesusercontrolformtemplate.html

    Kind regards,
    Sebastian
    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.
  5. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 22 Oct 2009 Link to this post

    Thanks, I have spent HOURS looking at that example even before posting my question. I simply need to know the grids datakeyfield for the selected piece of Equipment item so I can insert a new record. This really shouldn't be that difficult but I have to say, your examples do not have much in the way of explanations for us newbies.
  6. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 23 Oct 2009 Link to this post

    Hello AkAlan,

    I am sorry to hear that you are having a hard time finding the details you need in the available support resources.  The information you are searching for (how to extract primary key value from parent item in hierarchy on init insert) can be found in this article from the product documentation.

    Additionally, you may be interested in learning more about how to optimize your support resources searches from this blog post and the video/blog linked in the footer of my message.

    Kind regards,
    Sebastian
    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.
  7. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 23 Oct 2009 Link to this post

    Hi Sebastian, Thanks very much, I was able to get what I needed from that article. I was able to pass the parent key value to a session variable then grad it's value in the Load event of the UserControl. I'll look into your blog as well.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017