2009-01-27 32 views
0

问候!寻求建议:基于DropdownList值更新FormView

我正在寻找一些关于在FormView控件中基于DropDownList的选择在FormView中显示数据的方法的建议。例如,我有以下内容的用户控件:

<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>   

的用户控件的OnLoad()看起来像这样至今:

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

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

我希望能够通过的DropDownList的选择值项转换为GetMembershipTableXml()以检索相应的XML,然后使用它填充FormView的值。最好的办法是做什么?使用选定的DropDownList值作为查询字符串变量,将Response.Redirect返回到当前页面?我希望有更好的方法。你怎么看?

回答

1

您可以在DropDownList上为OnSelectedItemChanged创建一个事件;发生这种情况时,您可以抓取选定的项目,并调用GetMembershipTableXml函数。

最后,不要忘记调用DataBind您FormView控件更新值:)

认为这就是你以后,希望这有助于!

+0

我想我需要将我的代码当前放在我的OnLoad中的“if(!IsPostBack)”块中? – Bullines 2009-01-28 01:21:07