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

RadListView insertitemtemplate still showing after insert

3 Answers 187 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Dustin
Top achievements
Rank 1
Dustin asked on 09 Feb 2011, 07:39 PM
I have a pretty simple scenario using manual data operations with rad list view.  I insert an item into my collection in the ItemInserting event, the listview shows the new item but the insertitemtemplate is still showing.  Is my setup wrong?  Do I have to manually hide the thing?

Markup

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test2.aspx.vb" Inherits="Test2" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="rsm"></telerik:RadScriptManager>
    <div>
        <telerik:RadListView ID="rlv" runat="server" DataKeyNames="UserID" ItemPlaceholderID="itemPlaceholder" Height="400px" AllowPaging="true">
            <InsertItemTemplate>
                <tr>
                    <td>
                        <div style="vertical-align: middle; white-space: nowrap;">
                            <asp:LinkButton ID="btnInsert2" runat="server" Text="Insert" CommandName='<%# Telerik.Web.UI.RadListView.PerformInsertCommandName %>'></asp:LinkButton>
                            <asp:LinkButton ID="btnCancel2" runat="server" Text="Cancel" CommandName='<%# Telerik.Web.UI.RadListView.CancelCommandName %>'></asp:LinkButton>                           
                        </div>
                    </td>
                    <td>
                        <div style="vertical-align: middle; white-space: nowrap;">
                            <telerik:RadComboBox id="RadComboBox1" runat="server" autopostback="True" causesvalidation="False" allowcustomtext="True" backcolor="White" emptymessage="Select a Person" enableloadondemand="True" showmoreresultsbox="True" width="150px" dropdownwidth="200px" zindex="9002" enablescreenboundarydetection="False" style="margin-bottom: 0px" datatextfield="UserName" datavaluefield="pkUserID" filter="Contains" onitemsrequested="RCB_ItemsRequested">
                                        <CollapseAnimation Duration="200" Type="OutQuint" />
                                    </telerik:RadComboBox>
                        </div>
                    </td>
                </tr>
            </InsertItemTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Literal ID="lName" runat="server" Text='<%# Eval("UserName") %>'></asp:Literal>
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <asp:LinkButton ID="btnInsert" runat="server" CausesValidation="False" CommandName='<%# Telerik.Web.UI.RadListView.InitInsertCommandName %>' Text="Add User" />
                <table>
                    <tr>
                        <td style="border: ridge 1px lightgray">
                            <strong>Applicable Users</strong>
                            <table>
                                <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
                            </table>
                        </td>
                    </tr>                   
                </table>
            </LayoutTemplate>
        </telerik:RadListView>
    </div>
    </form>
</body>
</html>

Code Behind

Partial Class Test2
    Inherits System.Web.UI.Page
 
    Public Property Users As IList(Of UserInfo)
        Get
            Return If(ViewState("Users"), New List(Of UserInfo))
        End Get
        Set(ByVal value As IList(Of UserInfo))
            ViewState("Users") = value
        End Set
    End Property
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Me.Users = GetInitialUsers()
        End If
 
        rlv.DataSource = Users
        rlv.DataBind()
 
        Me.ViewState.SetItemDirty("Users", True)
    End Sub
 
    Private Function GetInitialUsers() As IList(Of UserInfo)
        Dim Users As New List(Of UserInfo)
 
        Users.Add(New UserInfo(1, "1"))
        Users.Add(New UserInfo(2, "2"))
        Users.Add(New UserInfo(3, "2"))
        Users.Add(New UserInfo(4, "4"))
 
        Return Users
    End Function
 
    Protected Sub RCB_ItemsRequested(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)
        Dim ComboBox As Telerik.Web.UI.RadComboBox = sender
 
        Dim itemOffset As Integer = e.NumberOfItems
        Dim NumberOfItems As Integer = 1000000000
        Dim Take As Integer = 20
 
        For i As Integer = 0 To Take
            ComboBox.Items.Add(New Telerik.Web.UI.RadComboBoxItem(i + itemOffset, (i + itemOffset).ToString))
        Next
 
        Dim NumberOfItemsInComboBox As Integer = e.NumberOfItems + ComboBox.Items.Count
 
        If NumberOfItems > 0 Then
            e.Message = [String].Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", NumberOfItemsInComboBox, NumberOfItems)
        Else
            e.Message = "No matches"
        End If
 
        e.EndOfItems = (NumberOfItemsInComboBox >= NumberOfItems)
    End Sub
 
    Protected Sub rlv_ItemInserting(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewCommandEventArgs) Handles rlv.ItemInserting
        Dim ComboBox As Telerik.Web.UI.RadComboBox = e.ListViewItem.FindControl("RadComboBox1")
 
        If Not String.IsNullOrWhiteSpace(ComboBox.SelectedValue) Then
            Dim UserID As Integer = ComboBox.SelectedValue
            Dim UserName As String = ComboBox.Text
 
            Me.Users.Add(New UserInfo(UserID, UserName))
        Else
            e.Canceled = True
        End If
 
    End Sub
 
    <Serializable()>
    Public Class UserInfo
        Private _UserID As Integer
        Private _UserName As String
 
        Public ReadOnly Property UserID As Integer
            Get
                Return _UserID
            End Get
        End Property
 
        Public ReadOnly Property UserName As String
            Get
                Return _UserName
            End Get
        End Property
 
        Public Sub New(ByVal UserID As Integer, ByVal UserName As String)
            _UserID = UserID
            _UserName = UserName
        End Sub
 
    End Class
 
End Class

I attached a couple of screen shots to illustrate my problem as well

3 Answers, 1 is accepted

Sort by
0
Dustin
Top achievements
Rank 1
answered on 09 Feb 2011, 11:44 PM
turns out if you change

Protected Sub rlv_ItemInserting(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewCommandEventArgs) Handles rlv.ItemInserting
        Dim ComboBox As Telerik.Web.UI.RadComboBox = e.ListViewItem.FindControl("RadComboBox1")
  
        If Not String.IsNullOrWhiteSpace(ComboBox.SelectedValue) Then
            Dim UserID As Integer = ComboBox.SelectedValue
            Dim UserName As String = ComboBox.Text
  
            Me.Users.Add(New UserInfo(UserID, UserName))
        Else
            e.Canceled = True
        End If
  
    End Sub

to

Protected Sub rlv_ItemInserting(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewCommandEventArgs) Handles rlv.ItemInserting
        Dim ComboBox As Telerik.Web.UI.RadComboBox = e.ListViewItem.FindControl("RadComboBox1")
  
        If Not String.IsNullOrWhiteSpace(ComboBox.SelectedValue) Then
            Dim UserID As Integer = ComboBox.SelectedValue
            Dim UserName As String = ComboBox.Text
  
            Me.Users.Add(New UserInfo(UserID, UserName))
            rlvSurveyAdministrators.InsertItemPosition = RadListViewInsertItemPosition.None
        Else
            e.Canceled = True
        End If
  
    End Sub

this problem goes away.  Not sure why
0
Coty
Top achievements
Rank 1
answered on 23 Feb 2011, 08:49 PM
I have this same problem.  The solution that you presented works for like a clearing procedure where you reset everything, otherwise it creates some odd things.

This seems like a very simple thing and maybe I am missing something, but I am looking for the opposite of this command:
RadListView1.ShowInsertItem()


Any ideas?  I have to be just overlooking something here...

thanks,

Coty
0
Princy
Top achievements
Rank 2
answered on 25 Feb 2011, 10:37 AM
Hello Coty,

Add the following code snippet in to ItemCommand event of ListView to hid ethe insert form.

C#:
protected void RadListView1_ItemCommand(object sender, Telerik.Web.UI.RadListViewCommandEventArgs e)
   {
       if ((e.CommandName == RadListView.PerformInsertCommandName) || (e.CommandName == RadListView.CancelCommandName))
       {
           RadListView1.InsertItemPosition = RadListViewInsertItemPosition.None;
        }
   }

Thanks,
Princy.
Tags
ListView
Asked by
Dustin
Top achievements
Rank 1
Answers by
Dustin
Top achievements
Rank 1
Coty
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or