Reputation: 99
I have a ListView & a DataTable (with Columns and Rows) that I have set as the Listview's DataSource & binded it, but my ListView will not display the data. ANy help? Thanks very much in advance
In thing.aspx :
<asp:ListView ID="lvInstructors" runat="server"
AutoGenerateColumns="False"
ShowRegularGridWhenEmpty="False"
EmptyDataText="No Sessions to Display."
OnRowDataBound="lvDataBound"
OnRowCommand="lvCommand"
Visible="true">
<LayoutTemplate>
<div class="container" id="mainContent">
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</div>
</LayoutTemplate>
<ItemTemplate>
<div class="row instructorItem">
<div class="col-2 sessionStartTimeDiv">
<p class="sessionStartTime"><%=SessionStartTime %></p>
</div>
<div class="col-2 instructorHeadshotDiv">
<asp:Image class="instructorHeadshot" runat="server" src="" />
</div>
<div class="col-5 sessionInfoDiv">
<h3 class="instructorName"><%=InstructorName%></h3>
<p class="sessionInfo"><%=SessionInfo%></p>
</div>
<div class="col-3 checkInBtnDiv">
<asp:Button class="checkInBtn" OnClick="CheckInBtn_Click"
ID="checkInBtn" runat="server" Text="CHECK-IN" />
</div>
</div>
</ItemTemplate>
<EmptyDataTemplate>
<br /><br />No Sessions to Display
</EmptyDataTemplate>
</asp:ListView>
In thing.aspx.cs :
//Make Data table to hold ListViewItem Data
DataTable dt = new DataTable();
dt.Columns.Add("SessionStartTime");
dt.Columns.Add("InstructorHeadshot");
dt.Columns.Add("InstructorName");
dt.Columns.Add("SessionInfo");
DataRow dr = dt.NewRow();
dr["SessionStartTime"] = "1:00:";
//dr["InstructorImage"] = "Bob";
dr["InstructorName"] = "Bob";
dr["SessionInfo"] = "Computer Room 2";
dt.Rows.Add(dr);
//Bind datatable to lv
lvInstructors.DataSource = dt;
lvInstructors.DataBind();
SideQuestion: (Not sure I need one here, but) When should I use a ListViewItem ?
Upvotes: 1
Views: 376
Reputation: 5068
You want to bind - #
- and Eval
.
<%# Eval("SessionStartTime") %>
Use this format for the other values/columns.
Upvotes: 2