2012-06-20 2 views
0

회사 및 고객의 선택에 따라 보고서를 생성합니다. 나는 회사를 위해 하나의 드롭 다운을 사용하고 회사에 따르면 고객이 표시됩니다. 그러나 여러 고객을 선택할 수있게하고 싶습니다. 사용자가 뷰 보고서의 버튼을 클릭하면 해당 선택 항목으로 쿼리 문자열을 업데이트하려고합니다. 고객 선택이 3 인 경우 쿼리 문자열을 사용하여 고객 코드를 전달하고 싶습니다. 정렬 쿼리 문자열은 고객의 선택에 따라 전송됩니다.드롭 다운에서 다중 선택 및 쿼리 문자열 업데이트

도와주세요.

감사합니다. 이 페이지에 다시 게시하지 않고 예를 도시

... 
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))); 
     } 
... 

:

Mitesh

선택 페이지 (영문)에서
+1

당신은 URL을 fron 자바 스크립트를 생성하고 거기에 가능한'location.href' – ivowiblo

+0

어떻게해야합니까? 제발 말해줘. –

+0

javascript의 "generate report"버튼에 onclick 이벤트를 추가하면 url을 생성하기위한 문자열이 연결됩니다. 'location.href = "/report.aspx?company="+ company + "& user ="+ user'와 같은 것입니다. 여기서'company'와'user'는'document.getElementById를 사용하여 얻은 드롭 다운리스트의 값입니다 ', jquery 또는 무엇인가 – ivowiblo

답변

0

: 당신의 Report.aspx.cs에서 다음

... 
<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 이벤트를 처리해야합니다.

관련 문제