处理嵌套 ListView 中的 DropDownList

发布于 2024-10-17 15:35:52 字数 1859 浏览 0 评论 0原文

我有两个嵌套的 .net ListView。我需要通过从外部列表视图的下拉列表中进行选择来过滤内部列表视图的内容。控件的布局如下:

<asp:listview id="lvOuter" runat="server" onitemdatabound="lvOuter_OnItemDataBound"
              onitemcommand="lvOuter_OnItemCommand" onitemcreated="lvOuter_ItemCreated" onselectedindexchanged="lvOuter_SelectedIndexChanged">
    <layouttemplate>
    <ul>
        <asp:placeholder id="itemPlaceholder" runat="server" />
    </ul>
    </layouttemplate>
    <itemtemplate>
        <asp:dropdownlist id="ddlTest" runat="server" onselectedindexchanged="ddlTerm_SelectedIndexChanged" autopostback="true" >
            <asp:listitem text="6" value="6"/>
            <asp:listitem text="9" value="9"/>
        </asp:dropdownlist>
        <asp:listview id="lvInner" runat="server" onselectedindexchanging="lvInner_SelectedIndexChanging"
                            onitemdatabound="lvInner_ItemDataBound" onitemcommand="lvInner_OnItemCommand">
             <layouttemplate>
                 <asp:placeholder id="itemPlaceholder" runat="server" />
             </layouttemplate>
             <itemtemplate>
                  <!--Results displayed here-->
              </itemtemplate>
          </asp:listview>
      </itemtemplate>
  </asp:listview>

在页面加载时,我将数据绑定到外部列表视图,在 OnItemDataBound 上,我绑定内部列表视图。

这一切都工作正常,但我现在需要做的是使用包含下拉列表中的参数的新查询重新绑定内部列表视图。当用户在下拉列表中选择新值时,就会发生这种情况。 (OnSelectedIndexChanged)

我可以通过发送者轻松访问该值,如下所示:

protected void ddlMyDropDown_OnSelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddlMyDropDown = sender as DropDownList;
    string value = ddlMyDropDown.SelectedValue;
}

但我无法找到与该下拉列表相关的内部列表视图,以便将新查询的结果与添加的 where 子句绑定。

我确信这一定是一个很常见的要求。任何指示将不胜感激。

I have two nested .net ListViews. I need to filter the contents of the inner listview by selecting from a dropdown list in the outer listview. The layout of the control is like this:

<asp:listview id="lvOuter" runat="server" onitemdatabound="lvOuter_OnItemDataBound"
              onitemcommand="lvOuter_OnItemCommand" onitemcreated="lvOuter_ItemCreated" onselectedindexchanged="lvOuter_SelectedIndexChanged">
    <layouttemplate>
    <ul>
        <asp:placeholder id="itemPlaceholder" runat="server" />
    </ul>
    </layouttemplate>
    <itemtemplate>
        <asp:dropdownlist id="ddlTest" runat="server" onselectedindexchanged="ddlTerm_SelectedIndexChanged" autopostback="true" >
            <asp:listitem text="6" value="6"/>
            <asp:listitem text="9" value="9"/>
        </asp:dropdownlist>
        <asp:listview id="lvInner" runat="server" onselectedindexchanging="lvInner_SelectedIndexChanging"
                            onitemdatabound="lvInner_ItemDataBound" onitemcommand="lvInner_OnItemCommand">
             <layouttemplate>
                 <asp:placeholder id="itemPlaceholder" runat="server" />
             </layouttemplate>
             <itemtemplate>
                  <!--Results displayed here-->
              </itemtemplate>
          </asp:listview>
      </itemtemplate>
  </asp:listview>

On the page load I bind data to the outer listview and on OnItemDataBound I bind the inner listview.

This is all working fine, but what I need to do now is to re-bind the inner listview with a new query that includes the parameter from the drop down list. This should happen when the user selects a new value in the drop downlist. (OnSelectedIndexChanged)

I can access the value easily enough through the sender, as so:

protected void ddlMyDropDown_OnSelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddlMyDropDown = sender as DropDownList;
    string value = ddlMyDropDown.SelectedValue;
}

but I'm unable to then find the inner listview relating to that dropdown in order to bind the results of the new query with the added where clause.

I'm sure this must be a pretty common requirement. Any pointers would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断念 2024-10-24 15:35:52

您是否尝试过使用类似 <%# Eval("value", "{0}") %>正如此处所见,

我似乎记得做了一些与您类似的事情。我已经有一段时间没有这样做了,如果这不准确,我很抱歉。

Have you tried using something like <%# Eval("value", "{0}") %> as seen here

I seem to recall doing something akin to yours with this. It has been awhile since I have done this so sorry if this is not accurate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文