views:

672

answers:

1

Greetings!

I'm looking for some advice regarding an approach to displaying data in a FormView based on a selection of a DropDownList within that FormView control. For example, I have a UserControl with the following:

<asp:XmlDataSource ID="xdsMyXmlData" runat="server" EnableCaching="false" XPath="Root/Membership" />
<asp:FormView ID="fvwMyFormView" runat="server" DataSourceID="xdsMyXmlData">
    <ItemTemplate>
        <div>
            <h2><%# XPath("Title") %></h2>

            <fieldset>
                <asp:DropDownList ID="ddlMemberTypes" runat="server" DataSource='<%# XPathSelect("MenuItems/*") %>'></asp:DropDownList>
            </fieldset>
            <table>
                <thead>
                    <tr>
                        <th><%# XPath("Columns/Name") %></th>
                        <th><%# XPath("Columns/Age") %></th>
                        <th><%# XPath("Columns/DateJoined")%></th>
                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="rptMembershipInfo" runat="server" DataSource='<%# XPathSelect("Members/*") %>'>
                        <ItemTemplate>
                            <tr>
                                <th><%# XPath("Data/Name") %></th>
                                <td><%# XPath("Data/Age") %></td>
                                <td><%# XPath("Data/DateJoined") %></td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </tbody>
            </table>
        </div>    
    </ItemTemplate>
</asp:FormView>

The UserControl's OnLoad() looks like this so far:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    string l_XmlData = MyControllerClass.GetMembershipTableXml(0);
    xdsMyXmlData.Data = l_XmlData;
}

I would like to be able to pass the value of the DropDownList's selected item into GetMembershipTableXml() in order to retrieve the corresponding XML and then use it to populate the values of the FormView. What would the best way be to do this? Doing a Response.Redirect back to the current page using the selected DropDownList value as a query string variable? I'm hoping there's a better approach. What do you think?

+1  A: 

You can create an event for OnSelectedItemChanged on your DropDownList; when this occurs, you can grab the selected item, and call your GetMembershipTableXml function.

Finally, dont forget to call DataBind on your FormView control to update the values :)

I think that's what you're after, hopefully it helps!

CapBBeard
I guess I would need to wrap my code currently in my OnLoad in a "if (!IsPostBack)" block?
Bullines
Hmm yeah, you probably will need to do that also, good point!
CapBBeard