Search code examples
asp.netvb.netlistviewdata-bindingcode-behind

ASP.NET: How do I set ListView data through the codebehind instead of using the Bind() function in the Text attribute?


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

Solution

  • use the ItemDataBound event.