开发者

Handling a DropDownList in a Nested ListView

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开发者_如何学Python 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜