Accessing values of fields in the InsertItemTemplate

7 posts, 0 answers
  1. James
    James avatar
    8 posts
    Member since:
    Dec 2012

    Posted 04 Jan 2015 Link to this post

    I am attempting to use the manual CRUD processing of data in my RadGrid via the DataForm.  I am using .net 4.5 and Visual Studo 2013, language VB.net. For the insert, I am able to display the insert form and enter data, the question I have is how to retrieve the entered values from the form in the code behind.  I want to interrogate the entered values and take some additional action before using a SQL stored procedure to insert the data.  The code from the _ItemInserting routine is:

            Dim sCatName as string
            Dim insertedItem As RadDataFormEditableItem = TryCast(e.DataFormItem, RadDataFormEditableItem)
            Dim newValues As New Hashtable()

            insertedItem.ExtractValues(newValues)

            For Each entry As DictionaryEntry In newValues

                sCatName = entry.Value

            Next

    In this case the entry.value is NULL.

    How do I get to the data?

    Thanks 
  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 07 Jan 2015 Link to this post

    Hi James,

    If you would like to perform manual CRUD operations wit RadDataForm try to follow the same approach as the one illustrated in the following article.

    In case the behavior persists please make a sample runnable project where the issue is replicated and send it in a support ticket. This way we would be able to investigate the issue locally and look for its cause.


    Regards,
    Viktor Tachev
    Telerik
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. James
    James avatar
    8 posts
    Member since:
    Dec 2012

    Posted 08 Jan 2015 in reply to Viktor Tachev Link to this post

    I will put together a project and submit it.  The hash table of extracted values is null 
  5. Simon
    Simon avatar
    12 posts
    Member since:
    Nov 2014

    Posted 09 Jan 2015 Link to this post

    Samething happen to me.

    Im using c#.

    protected void RadDataForm1_ItemInserting(object sender, RadDataFormCommandEventArgs e)
       {
     
           RadDataFormEditableItem insertedItem = e.DataFormItem as RadDataFormEditableItem;
           Hashtable newValues = new Hashtable();
           insertedItem.ExtractValues(newValues);
     
           RopackNews.DataModel.NewsData test = new RopackNews.DataModel.NewsData();
           test.Createur = newValues["Createur"].ToString();
           test.DateCreation = DateTime.Now;
     
           using (RopackNewsEntities context = new RopackNewsEntities())
           {
               context.NewsData.Add(test);
           }
     
       }
     
       protected void Test2_FileUploaded(object sender, FileUploadedEventArgs e)
       {
           RadDataFormEditableItem editItem = ((Telerik.Web.UI.RadWebControl)(sender)).NamingContainer as RadDataFormEditableItem;
           RadBinaryImage bImg = editItem.FindControl("RadBinaryImage1") as RadBinaryImage;
           byte[] image;
           long fileLength = e.File.InputStream.Length;
           image = new byte[fileLength];
           e.File.InputStream.Read(image, 0, image.Length);
           bImg.DataValue = image;
       }
     
       public IQueryable<NewsData> SelMethod()
       {
           if (RadGrid1.SelectedValue != null)
           {
               int column2 = (int)RadGrid1.SelectedValue;
     
               var newsSelected = from p in context.NewsData
                                  where p.ID == column2
                                  orderby p.ID
                                  select p;
               return newsSelected;
           }
           return null;
       }
     
        
       protected void RadDataForm1_NeedDataSource(object sender, RadDataFormNeedDataSourceEventArgs e)
       {
           RadDataForm1.DataSource = SelMethod();
       }
     
       protected void RadDataForm1_PreRender(object sender, EventArgs e)
       {
           RadDataForm1.Rebind();
       }
  6. Simon
    Simon avatar
    12 posts
    Member since:
    Nov 2014

    Posted 09 Jan 2015 in reply to Simon Link to this post

    Sorry, I can't edit my own post. It crash because the newValues is null.
    (don't bother about the FileUploaded, it's some old code)

    Here the HTML Markup.

    <telerik:RadDataForm ID="RadDataForm1" runat="server"  OnNeedDataSource="RadDataForm1_NeedDataSource" OnPreRender="RadDataForm1_PreRender"
                        DataKeyNames="ID"   OnItemInserting="RadDataForm1_ItemInserting">
                        <LayoutTemplate>
                            <div class="RadDataForm rdfLeftAligned rdfNoFieldHint rdfNoFieldHint">
                                <div id="itemPlaceholder" runat="server">
                                </div>
                            </div>
                        </LayoutTemplate>
     
                        <ItemTemplate>
                            <fieldset>
                                <legend>Détail</legend>
                                <div class="rdfRow">
                                    <asp:Label ID="TypeIDLabel2" runat="server" CssClass="rdfLabel" Text="Type"></asp:Label>
                                    <asp:Label ID="Label1" runat="server" CssClass="rdfFieldValue" Text='<%# Eval("NewsType.Description") %>' />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="TitreLabel2" runat="server" CssClass="rdfLabel" Text="Titre"></asp:Label>
                                    <asp:Label ID="TitreLabel1" runat="server" CssClass="rdfFieldValue" Text='<%# Eval("Titre") %>' />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="DatePublicationLabel2" runat="server" CssClass="rdfLabel" Text="Date de publication"></asp:Label>
                                    <asp:Label ID="DatePublicationLabel1" runat="server" CssClass="rdfFieldValue" Text='<%# Eval("DatePublication") == null ? "Non publiée" : Eval("DatePublication" , "{0:yyyy/MM/dd}") %>' />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="DescriptionCourteLabel2" runat="server" CssClass="rdfLabel" Text="Description courte:"></asp:Label>
                                    <asp:Label ID="DescriptionCourteLabel1" runat="server" CssClass="rdfFieldValue" Text='<%# Eval("DescriptionCourte") %>' />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="DescriptionLongueLabel2" runat="server" CssClass="rdfLabel" Text="Description longue"></asp:Label>
                                    <asp:Label ID="DescriptionLongueLabel1" runat="server" CssClass="rdfFieldValue" Text='<%# Eval("DescriptionLongue") %>' />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="CreateurLabel2" runat="server" CssClass="rdfLabel" Text="Créateur"></asp:Label>
                                    <asp:Label ID="CreateurLabel1" runat="server" CssClass="rdfFieldValue" Text='<%# Eval("Createur") %>' />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="ImageFilenameLabel2" runat="server" CssClass="rdfLabel" Text="Nom de l'image"></asp:Label>
                                    <asp:Label ID="ImageFilenameLabel1" runat="server" CssClass="rdfFieldValue" Text='<%# Eval("ImageFilename") %>' />
                                </div>
                                <div class="rdfCommandButtons">
                                    <hr class="rdfHr" />
                                    <telerik:RadButton ID="InitInsertButton" runat="server" ButtonType="SkinnedButton" CausesValidation="False" CommandName="InitInsert" Text="Nouveau" ToolTip="Nouveau" />
                                    <telerik:RadButton ID="EditButton" runat="server" ButtonType="SkinnedButton" CausesValidation="False" CommandName="Edit" Text="Modifier" ToolTip="Modifier" />
                                </div>
                            </fieldset>
                        </ItemTemplate>
     
                        <EditItemTemplate>
                            <fieldset>
                                <legend class="rdfLegend">Édition</legend>
                                <div class="rdfRow">
                                    <asp:Label ID="TypeIDLabel2" runat="server" AssociatedControlID="TypeIDComboBox" CssClass="rdfLabel" Text="Type"></asp:Label>
                                    <telerik:RadComboBox ID="TypeIDComboBox" runat="server" DataSourceID="EntityDataSource3" DataTextField="Description" DataValueField="ID" SelectedValue='<%# Bind("TypeID")%>'
                                        AutoPostBack="true" OnSelectedIndexChanged="TypeIDComboBox_SelectedIndexChanged1" ></telerik:RadComboBox>
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="TitreLabel2" runat="server" AssociatedControlID="TitreTextBox" CssClass="rdfLabel" Text="Titre"></asp:Label>
                                    <telerik:RadTextBox ID="TitreTextBox" runat="server" Text='<%# Bind("Titre") %>' WrapperCssClass="rdfInput" />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="DatePublicationLabel2" runat="server" AssociatedControlID="DatePublicationLabel1" CssClass="rdfLabel" Text="Date de publication"></asp:Label>
                                    <asp:Label ID="DatePublicationLabel1" runat="server" CssClass="rdfFieldValue" Text='<%# Eval("DatePublication" , "{0:yyyy/MM/dd}") %>' />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="DescriptionCourteLabel2" runat="server" AssociatedControlID="DescriptionCourteTextBox" CssClass="rdfLabel" Text="Description courte"></asp:Label>
                                    <telerik:RadTextBox ID="DescriptionCourteTextBox" runat="server" Text='<%# Bind("DescriptionCourte") %>' WrapperCssClass="rdfInput" TextMode="MultiLine"/>
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="DescriptionLongueLabel2" runat="server" AssociatedControlID="DescriptionLongueTextBox" CssClass="rdfLabel" Text="Description longue"></asp:Label>
                                    <telerik:RadTextBox ID="DescriptionLongueTextBox" runat="server" Text='<%# Bind("DescriptionLongue") %>' WrapperCssClass="rdfInput" TextMode="MultiLine" Height="150px"/>
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="CreateurLabel2" runat="server" AssociatedControlID="CreateurTextBox" CssClass="rdfLabel" Text="Créateur"></asp:Label>
                                    <telerik:RadTextBox ID="CreateurTextBox" runat="server" Text='<%# Bind("Createur") %>' WrapperCssClass="rdfInput" />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="ImageFilenameLabel2" runat="server" AssociatedControlID="ImageFilenameTextBox" CssClass="rdfLabel" Text="Nom de l'image"></asp:Label>
                                    <telerik:RadTextBox ID="ImageFilenameTextBox" runat="server" Text='<%# Bind("ImageFilename") %>' WrapperCssClass="rdfInput" />
                                </div>
                                <div class="rdfCommandButtons">
                                    <hr class="rdfHr" />
                                    <telerik:RadButton ID="UpdateButton" runat="server" ButtonType="SkinnedButton" CommandName="Update" Text="Enregistrer" ToolTip="Enregistrer" />
                                    <telerik:RadButton ID="CancelButton" runat="server" ButtonType="SkinnedButton" CausesValidation="False" CommandName="Cancel" Text="Annuler" ToolTip="Annuler" />
                                </div>
                            </fieldset>
                        </EditItemTemplate>
     
                        <InsertItemTemplate>
                            <fieldset>
                                <legend class="rdfLegend">Nouveau</legend>
                                <div class="rdfRow">
                                    <asp:Label ID="TypeIDLabel2" runat="server" AssociatedControlID="TypeIDComboBox" CssClass="rdfLabel" Text="Type"></asp:Label>
                                    <telerik:RadComboBox ID="TypeIDComboBox" runat="server" DataSourceID="EntityDataSource3" DataTextField="Description"
                                        DataValueField="ID" AutoPostBack="true"></telerik:RadComboBox>
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="TitreLabel2" runat="server" AssociatedControlID="TitreTextBox" CssClass="rdfLabel" Text="Titre"></asp:Label>
                                    <telerik:RadTextBox ID="TitreTextBox" runat="server" WrapperCssClass="rdfInput" Text='<%# Bind("Titre") %>' />
                                </div>
                                <%--<div class="rdfRow" style="display:none;">
                                    <asp:Label ID="DatePublicationLabel2" runat="server" AssociatedControlID="DatePublicationLabel1" CssClass="rdfLabel" Text="Date de publication"></asp:Label>
                                    <asp:Label ID="DatePublicationLabel1" runat="server" CssClass="rdfFieldValue" Text='<%# Eval("DatePublication" , "{0:yyyy/M/d}") %>' />
                                </div>--%>
                                <%--<div class="rdfRow" style="display:none;">
                                    <asp:Label ID="DateCreationLabel2" runat="server" AssociatedControlID="DateCreationTextBox" CssClass="rdfLabel" Text="Date création"></asp:Label>
                                    <telerik:RadDatePicker ID="DateCreationTextBox" runat="server" CssClass="rdfPicker"
                                        DbSelectedDate='<%# Bind("DateCreation") %>' MinDate="<%#new DateTime(1900, 1, 1) %>"
                                        SharedCalendarID='<%# Container.OwnerDataForm.FindControl("rdfSharedCalendar").UniqueID %>'
                                        SharedTimeViewID='<%# Container.OwnerDataForm.FindControl("rdfSharedTimeView").UniqueID %>'  DateInput-ReadOnly="true"/>
                                </div>--%>
                                <div class="rdfRow">
                                    <asp:Label ID="DescriptionCourteLabel2" runat="server" AssociatedControlID="DescriptionCourteTextBox" CssClass="rdfLabel" Text="Description courte"></asp:Label>
                                    <telerik:RadTextBox ID="DescriptionCourteTextBox" runat="server" WrapperCssClass="rdfInput" TextMode="MultiLine" Text='<%# Bind("DescriptionCourte") %>' />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="DescriptionLongueLabel2" runat="server" AssociatedControlID="DescriptionLongueTextBox" CssClass="rdfLabel" Text="Description longue"></asp:Label>
                                    <telerik:RadTextBox ID="DescriptionLongueTextBox" runat="server"  WrapperCssClass="rdfInput" TextMode="MultiLine" Height="150px" Text='<%# Bind("DescriptionLongue") %>'/>
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="CreateurLabel2" runat="server" AssociatedControlID="CreateurTextBox" CssClass="rdfLabel" Text="Createur"></asp:Label>
                                    <telerik:RadTextBox ID="CreateurTextBox" runat="server"  WrapperCssClass="rdfInput" />
                                </div>
                                <div class="rdfRow">
                                    <asp:Label ID="Label2" runat="server" AssociatedControlID="Test2" CssClass="rdfLabel" Text="Image"></asp:Label>
                                    <telerik:RadAsyncUpload runat="server" ID="Test2" OnClientFileUploaded="OnClientFilesUploaded" Width="100%"
                                        AllowedFileExtensions="jpg,jpeg,png,gif" MaxFileSize="1048576" OnFileUploaded="Test2_FileUploaded" MaxFileInputsCount="1">
                                    </telerik:RadAsyncUpload>
                                        <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1"
                                            AutoAdjustImageControlSize="false" Width="90px" Height="110px" ToolTip="hh"
                                            AlternateText="hh" />
                                     
                                </div>
                                <div class="rdfCommandButtons">
                                    <hr class="rdfHr" />
                                    <telerik:RadButton ID="PerformInsertButton" runat="server" ButtonType="SkinnedButton" CommandName="PerformInsert" Text="Sauvegarder" ToolTip="Sauvergarder" />
                                    <telerik:RadButton ID="CancelButton" runat="server" ButtonType="SkinnedButton" CausesValidation="False" CommandName="Cancel" Text="Annuler" ToolTip="Annuler" />
                                </div>
                            </fieldset>
                        </InsertItemTemplate>
                         
                        <EmptyDataTemplate>
                            <div>
                                <div class="rdfEmpty">
                                    There are no items to be displayed.
                                </div>
                            </div>
                        </EmptyDataTemplate>
     
                    </telerik:RadDataForm>
  7. Simon
    Simon avatar
    12 posts
    Member since:
    Nov 2014

    Posted 09 Jan 2015 Link to this post

    I used one of your scenario and copy pasted the code to ry out the manual CRUD...
    Same as James.

    Dim insertedItem As RadDataFormEditableItem = TryCast(e.DataFormItem, RadDataFormEditableItem)

    I switched RadDataFormEditableItem to RadDataFormInsertItem and evrything works fine now.


  8. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 13 Jan 2015 Link to this post

    Hi Simon,

    I am glad to hear that the issue was resolved. Thank you for sharing your experience with the community.

    Regards,
    Viktor Tachev
    Telerik
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017