我需要使用来自另一个函数的 3 个字符串创建和填充 ListView。我还希望能够在运行时选择多条数据来更改它们的值(ListView 可以吗?)。
我已经在网上到处寻找这方面的信息,但我似乎找不到任何信息。如果有人能给我一些关于执行此操作的最佳方法的见解,我将不胜感激。
我也在 GridView 上看到过一些东西。这对这个应用程序会更好吗?
我需要使用来自另一个函数的 3 个字符串创建和填充 ListView。我还希望能够在运行时选择多条数据来更改它们的值(ListView 可以吗?)。
我已经在网上到处寻找这方面的信息,但我似乎找不到任何信息。如果有人能给我一些关于执行此操作的最佳方法的见解,我将不胜感激。
我也在 GridView 上看到过一些东西。这对这个应用程序会更好吗?
我必须承认我不知道你到底在问什么。但是,是的,您可以将 3 个字符串绑定到ListView
来自“另一个函数”的 :)
您可以处理ItemDataBound
更改 ListItems 中的值:
<asp:ListView runat="server" ID="ListView1" >
<LayoutTemplate>
<table>
<thead>
<tr>
<th>
A String
</th>
</tr>
</thead>
<tbody>
<asp:PlaceHolder runat="server" ID="itemPlaceholder" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="LblString" Text="<%# Container.DataItem %>" runat="server"></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
该页面的代码隐藏:
Public Class ListView
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.ListView1.DataSource = OtherFuntion()
Me.ListView1.DataBind()
End If
End Sub
Private Function OtherFuntion() As IEnumerable(Of String)
Return {"String 1", "String 2", "String 3"}
End Function
Private Sub ListView1_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound
If e.Item.ItemType = ListViewItemType.DataItem Then
Dim lblString = DirectCast(e.Item.FindControl("LblString"), Label)
lblString.Text = New String(lblString.Text.Reverse.ToArray)
End If
End Sub
End Class
这只是反转所有字符串。