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

Insert Record using UserControl

5 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AkAlan
Top achievements
Rank 2
AkAlan asked on 21 Oct 2009, 09:48 PM
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" /> 


5 Answers, 1 is accepted

Sort by
0
AkAlan
Top achievements
Rank 2
answered on 21 Oct 2009, 10:54 PM
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.  

 

 

 

 

0
Sebastian
Telerik team
answered on 22 Oct 2009, 08:51 AM
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.
0
AkAlan
Top achievements
Rank 2
answered on 22 Oct 2009, 05:04 PM
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.
0
Sebastian
Telerik team
answered on 23 Oct 2009, 10:35 AM
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.
0
AkAlan
Top achievements
Rank 2
answered on 23 Oct 2009, 04:45 PM
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.
Tags
Grid
Asked by
AkAlan
Top achievements
Rank 2
Answers by
AkAlan
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or