我有一个列表视图和一个下拉列表(它保存在列表视图之外)和一个搜索按钮。
现在我需要从 listview 访问两个文字控件,它们保存在布局模板和 emptydatatemplate 中,并将下拉列表值分配给那些带有少量额外文本的文字控件。
我尝试的是布局模板:
protected void lvP_LayoutCreated(object sender, EventArgs e)
{
if (dlCategory.SelectedIndex != -1)
{
(lvP.FindControl("ltHeaderText") as Literal).Text = " Products in " + dlCategory.SelectedItem.Text.ToString();
}
}
对于空数据,我在下面尝试
protected void lvPr_ItemCreated(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.EmptyItem)
{
(lvP.FindControl("ltEmptyData") as Literal).Text = "No products in " + dlCategory.SelectedItem.Text.ToString();
}
}
aspx 标记
<asp:ListView ID="lvP" runat="server" OnLayoutCreated="lvP_LayoutCreated"
OnItemCreated="lvP_ItemCreated">
<LayoutTemplate>
<table class="PWorld" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>
<span>
<asp:Literal ID="ltHeaderText" runat="server"></asp:Literal>
</span>
</th>
</tr>
</thead>
<tbody>
<tr id="itemplaceHolder" runat="server">
</tr>
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr valign="top">
<td>
<table class="PWorldInner" cellpadding="0" cellspacing="0">
<tr>
<td>
<img height="65px" width="175px" src='<%#Eval("ProductLogo")%>' alt="<%#Eval("pName")%>" />
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<asp:Literal ID="ltEmptyData" runat="server"></asp:Literal>
</EmptyDataTemplate>
</asp:ListView>