ASP.NET:如何通过代码隐藏设置 ListView 数据,而不是使用 Text 属性中的 Bind() 函数?
如何通过代码隐藏设置 ListView 数据,而不是使用 Text 属性中的 Bind() 函数?
现在我正在执行以下操作,但我想在代码隐藏中检索并设置它。我正在使用 VB...谢谢!
<asp:Label ID="Date" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
编辑:
抱歉,我按照以下方式将数据与数据表绑定。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ListView.DataSource = MyDataTable
ListView.DataBind()
End If
End Sub
How do I set ListView data through the codebehind instead of using the Bind() function in the Text attribute?
Right now I'm doing the following, but I'd like to have it retrieved and set in the codebehind. I'm using VB... Thanks!
<asp:Label ID="Date" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
Edit:
Sorry, I'm binding the data in the following way with a DataTable.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ListView.DataSource = MyDataTable
ListView.DataBind()
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 ItemDataBound 事件。
use the ItemDataBound event.
在没有看到您的代码的情况下,我可以告诉您 ListView 有一个 DataSource 属性,您应该能够在加载代码中设置该属性(然后执行 DataBind())。我知道我以前用 GridView 做过这样的事情。
Without seeing your code, I can tell you that a ListView has a DataSource property that you should just be able to set in your load code (and then do a DataBind()). I know I've done that before with a GridView.
根据您提供的信息,这是我能给您的最好的信息。您可能希望将此代码段放入 ListView 的 PreRender 事件中。
Based on the info you have provided this is the best I can give you. You may want to put this snippet in the PreRender event for your ListView.