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

client side (insertItem)

3 Answers 108 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Michael Pullella
Top achievements
Rank 1
Michael Pullella asked on 01 Apr 2010, 02:31 PM
Hi...

I have a listview on a page, I am trying to add an item via javascript with insertItem().  What params am I supposed to give to the method in order to add an item?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" /> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
        <Scripts> 
            <%--Needed for JavaScript IntelliSense in VS2010--%> 
            <%--For VS2008 replace RadScriptManager with ScriptManager--%> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" /> 
        </Scripts> 
    </telerik:RadScriptManager> 
    <script type="text/javascript">  
        //Put your Java Script code here.  
    </script> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
    </telerik:RadAjaxManager> 
   
    <telerik:RadSkinManager ID="RadSkinManager1" Runat="server" Skin="Outlook">  
    </telerik:RadSkinManager> 
    <div> 
 
        <telerik:RadListView ID="RadListView1" runat="server"   
            DataSourceID="AccessDataSource1" Skin="Office2007">  
            <AlternatingItemTemplate> 
                <div class="rlvA">  
                    <img src="images/book.png" />&nbsp;<asp:Label ID="Field1Label" runat="server" Text='<%# Eval("Field1") %>' /> 
                </div> 
            </AlternatingItemTemplate> 
            <ItemTemplate> 
                <div class="rlvI">  
                    <img src="images/book.png" />&nbsp;<asp:Label ID="Field1Label" runat="server" Text='<%# Eval("Field1") %>' /> 
                </div> 
            </ItemTemplate> 
            <EmptyDataTemplate> 
                <div class="RadListView RadListView_Office2007">  
                    <div class="rlvEmpty">  
                        There are no items to be displayed.</div> 
                </div> 
            </EmptyDataTemplate> 
            <LayoutTemplate> 
                <div class="RadListView RadListView_Office2007">  
                    <div ID="itemPlaceholder" runat="server">  
                    </div> 
                </div> 
            </LayoutTemplate> 
            <SelectedItemTemplate> 
                <div class="rlvISel">  
                    &nbsp;<asp:Label ID="Field1Label" runat="server" Text='<%# Eval("Field1") %>' /> 
                </div> 
            </SelectedItemTemplate> 
        </telerik:RadListView> 
        <asp:AccessDataSource ID="AccessDataSource1" runat="server"   
            DataFile="~/App_Data/Database.mdb" SelectCommand="SELECT [Field1] FROM [NAMES]">  
        </asp:AccessDataSource> 
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="InsertNewItem()" /> 
          
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
        <script type="text/javascript">  
            function InsertNewItem() {  
                alert("What params am I supposed to pass in order to have the listview insert a row for me?");  
                var listView = $find("<%= RadListView1.ClientID %>");  
                listView.insertItem();  
            }  
        </script> 
        </telerik:RadCodeBlock> 
    </div> 
    </form> 
</body> 
</html> 
 

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 01 Apr 2010, 04:22 PM
Hello Michael,

insertItem client-side method is meant to trigger PerformInsertCommand, thus it is doing the same thing as clicking on insert button in the insert form. Therefore in order to use it you should show the InsertItem first, then after user enters some data you can call insertItem() method to submit the form to the server.

I hope this helps.
Rosen
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.
0
Phani
Top achievements
Rank 1
answered on 24 Jul 2015, 08:23 AM

How to display InsertItem using Javascript? Please help.

 

Thanks,

Phani

0
Maria Ilieva
Telerik team
answered on 28 Jul 2015, 03:27 PM
Hello Phani,

In orders to achieve the required functionality you can use the fireCommand () method and fire InitInsert command as described below:
http://docs.telerik.com/devtools/aspnet-ajax/controls/listview/client-side-programming/radlistview/methods/firecommand


Regards,
Maria Ilieva
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
ListView
Asked by
Michael Pullella
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Phani
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or