Unable to activate the InsertItemTemplate

2 posts, 0 answers
  1. david
    david avatar
    1 posts
    Member since:
    Jun 2014

    Posted 27 Jun 2014 Link to this post

    Hi,

    I am trying to activate the InsertItemTemplate using button cmdAdd but I can't have it activated. What am I doing wrong?

    Thanks in advance,
    David

    The Webform:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
      <title></title>
    </head>
    <body>
      <form id="form1" runat="server">
      <telerik:RadScriptManager runat="server" ID="rsm"></telerik:RadScriptManager>
        <div>
          <telerik:RadListView ID="RadListView1" runat="server" ItemPlaceholderID="panel1">
            <LayoutTemplate>
              <fieldset>
                <table>
                  <tr>
                    <td>
                      <asp:Label ID="lblHeader01" runat="server" Text="header01" Width="160"></asp:Label></td>
                    <td>
                      <asp:Label ID="lblHeader02" runat="server" Text="header02" Width="160"></asp:Label></td>
                  </tr>
                </table>
                <panel id="panel1" runat="server"></panel>
                <asp:Button ID="cmdAdd" runat="server" Text="Add" OnClick="cmdAdd_Click"></asp:Button>
              </fieldset>
            </LayoutTemplate>
            <ItemTemplate>
              <fieldset>
                <table>
                  <tr>
                    <td>
                      <telerik:RadTextBox ID="txtItem01" runat="server" Text='<%# Eval("field01") %>'></telerik:RadTextBox>
                      <td>
                        <telerik:RadTextBox ID="txtItem02" runat="server" Text='<%# Eval("field02") %>'></telerik:RadTextBox>
                      </td>
                  </tr>
                </table>
              </fieldset>
            </ItemTemplate>
            <EditItemTemplate>
              <fieldset>
                <table>
                  <tr>
                    <td>
                      <telerik:RadTextBox ID="Edit01" runat="server" Text='<%# Bind("field01")%>'></telerik:RadTextBox></td>
                    <td>
                      <telerik:RadTextBox ID="Edit02" runat="server" Text='<%# Bind("field02")%>'></telerik:RadTextBox></td>
                  </tr>
                </table>
              </fieldset>
            </EditItemTemplate>
            <InsertItemTemplate>
              <table>
                <tr>
                  <td>
                    <telerik:RadTextBox ID="Insert01" runat="server" Resize="None" Text='<%# Eval("field01")%>'></telerik:RadTextBox></td>
                  <td>
                    <telerik:RadTextBox ID="Insert02" runat="server" Resize="None" Text='<%# Eval("field02")%>'></telerik:RadTextBox></td>
                </tr>
              </table>
            </InsertItemTemplate>
          </telerik:RadListView>
          <br />
        </div>
      </form>
    </body>
    </html>

    The Code Behind:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    namespace xxx
    {
      public partial class Test4 : System.Web.UI.Page
      {
        public class myExpedClass
        {
          public string field01 { get; set; }
          public string field02 { get; set; }
        }
        myExpedClass myExpedObject;
        List<myExpedClass> myList;
        protected void Page_Load(object sender, EventArgs e)
        {
          if (!IsPostBack)
          {
            // Instantiate
            myList = new List<myExpedClass>();
            // Record 01
            myExpedObject = new myExpedClass();
            myExpedObject.field01 = "R1C1";
            myExpedObject.field02 = "R1C2";
            myList.Add(myExpedObject);
            // Record 02
            myExpedObject = new myExpedClass();
            myExpedObject.field01 = "R2C1";
            myExpedObject.field02 = "R2C2";
            myList.Add(myExpedObject);
            // Link the list to the RadListView
            RadListView1.DataSource = myList;
            RadListView1.DataBind();
          }
        }
        protected void cmdAdd_Click(object sender, EventArgs e)
        {
          // Show InsertItemTemplate
          RadListView1.ShowInsertItem();
        }
      }
    }
  2. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 01 Jul 2014 Link to this post

    Hello David,

    Please note that performing complex list view operations such as Inserting, Deleting, Updating, Grouping, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations. Therefore, we suggest you to avoid Simple Databinding (DataBind() method) and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
      Declarative DataSource
      Advanced Data Binding
    (NeedDataSource event)

    Hope this helps. Please make the suggested modification and let me know about the result.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top