我有一个非常简单的场景,使用rad list view进行手动数据操作。我在ItemInserting事件中将一个项目插入到我的集合中,listview显示了新项目,但仍然显示了insertitemtemplate。我的设置错了吗?我必须手动隐藏这个东西吗?
标记
<%@ 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">
<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="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>
背后的代码
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
答案 0 :(得分:1)
插入新项目后,将InsertItemPosition
设置为None
:
RadListView1.InsertItemPosition = RadListViewInsertItemPosition.None
答案 1 :(得分:0)
radlistview1.IsItemInserted = FALSE;
保存后单击或设置e.canceled = false