0

選択した会社とその顧客に応じてレポートを作成します。私は会社に 1 つのドロップダウンを使用し、会社に応じて顧客が表示されます。ただし、複数の顧客を選択できるようにして、ユーザーがレポートを表示するボタンをクリックしたときに、その選択でクエリ文字列を更新したいと考えています。顧客の選択が 3 つの場合、クエリ文字列を使用して顧客コードを渡したいと思います。並べ替えクエリ文字列は、顧客の選択に従って送信されます。

私を助けてください。

ありがとうございます。

ミテシュ

4

1 に答える 1

0

選択ページ(aspx):

...
<script type="text/javascript">
        function submitSelection() {
            var customerList = document.getElementById('<%= lbCustomers.ClientID %>');
            var companyList = document.getElementById('<%= lbCompany.ClientID %>');
            var selectedCustomerQuery = [];
            for (var i = 0; i < customerList.options.length; i++) {                
                if (customerList.options[i].selected)
                    selectedCustomerQuery.push('customer_id=' + customerList.options[i].value);
            }
            location.href = 'Report.aspx?company_id=' + companyList.value + '&' + selectedCustomerQuery.join('&');
        }
    </script>
        <asp:DropDownList ID="lbCompany" runat="server" SelectionMode="Single" >
        <asp:ListItem Value="1">Company 1</asp:ListItem>
        <asp:ListItem Value="2">Company 2</asp:ListItem>
    </asp:DropDownList><br />
    <asp:ListBox ID="lbCustomers" runat="server" SelectionMode="Multiple">
        <asp:ListItem Text="John" Value="1"></asp:ListItem>
        <asp:ListItem Text="Paul" Value="2"></asp:ListItem>
        <asp:ListItem Text="Peter" Value="3"></asp:ListItem>
    </asp:ListBox><br />
    <input id="Button1" type="button" value="View Report" onclick="submitSelection()" />
...

次に、Report.aspx.csで:

...
protected void Page_Load(object sender, EventArgs e)
        {
            var selectedCompany = Request.QueryString["company_id"];
            //get passed selected customers, will be stored in an array
            var selectedCustomers = Request.QueryString.GetValues("customer_id");

            Response.Write(string.Format("Company ID: {0}, Customers: {1}", selectedCompany.ToString(), string.Join(",", selectedCustomers)));
        }
...

これは、ページにポストバックしない例を示しています。コードビハインドの他のロジックを処理するためにポストバックする必要がある場合は、<input>ボタンをASP.NETボタンコントロールに変更し、そのOnClickイベントを処理する必要があります。

于 2012-06-20T07:04:48.470 に答える