C# 下拉列表中的多项选择和更新查询字符串

C# 下拉列表中的多项选择和更新查询字符串,c#,C#,我根据选择的公司及其客户生成报告。我为公司使用一个下拉列表,根据公司显示客户。但是,我希望能够选择多个客户,当用户单击查看报告的按钮时,我希望使用该选择更新查询字符串。如果选择的客户是三个,我想使用查询字符串传递他们的客户代码。根据客户的选择发送分类查询字符串 请帮帮我 谢谢和问候 在您的选择页面aspx中的Mitesh: ... <script type="text/javascript"> function submitSelection() {

我根据选择的公司及其客户生成报告。我为公司使用一个下拉列表,根据公司显示客户。但是,我希望能够选择多个客户,当用户单击查看报告的按钮时,我希望使用该选择更新查询字符串。如果选择的客户是三个,我想使用查询字符串传递他们的客户代码。根据客户的选择发送分类查询字符串

请帮帮我

谢谢和问候


在您的选择页面aspx中的Mitesh

...
<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()" />
...

这说明了一个没有发回页面的示例。如果需要回发来处理代码中的其他逻辑,您必须将按钮更改为ASP.NET按钮控件,并处理其OnClick事件。

您需要从javascript生成url,然后使用location.hrefhow可能吗?请告诉我。将OnClick事件添加到javascript中的generate report按钮,并连接用于创建url的字符串。类似location.href=/report.aspx?company=+company+&user=+user,其中company和user是使用document.getElementById、jquery或其他方法获得的下拉列表的值
...
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)));
        }
...