访问下拉列表值保留在listview之外?

时间:2013-04-15 08:28:53

标签: asp.net c#-4.0 asp.net-4.0

我有一个列表视图和一个下拉列表(这是在listview之外)和一个搜索按钮。

现在我需要从listview访问两个文字控件,它们保存在布局模板和emptydatatemplate中,并将dropdownlist值分配给那些文字控件,只需要很少的额外文本。

我尝试的是布局模板:

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>

0 个答案:

没有答案
相关问题