DropDownList無重新整理二級聯動(.ashx)
阿新 • • 發佈:2019-02-06
我做的功能是,選擇供應商,帶出對應的付款方式。
Default.aspx 預設頁面
注:EnableEventValidation="false"一定要有,否則就黃了。<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Module_FFY_LetterOfCredit_Default" EnableEventValidation="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>無標題頁</title> <script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" language="javascript"></script> <script src="../../../js/jquery-ui-1.7.2.custom.min.js" type="text/javascript" language="javascript"></script> <script type="text/javascript"> $(document).ready(function() { $.post('SupHandler.ashx', {}, function(data) { $("#DropDownList1").html(data) }, 'html'); $.post('PayModeHandler.ashx', {supCode:""}, function(data) { $("#DropDownList2").html(data) }, 'html'); $("#DropDownList1").change(function() { $.post('PayModeHandler.ashx', {supCode:$(this).val()}, function(data) { $("#DropDownList2").empty().html(data) }, 'html'); }); }); </script> </head> <body> <form id="form1" runat="server"> <div> 供應商: <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> <br /> 付款方式:<asp:DropDownList ID="DropDownList2" runat="server"> </asp:DropDownList> <br /> <asp:Button ID="Button1" runat="server" Text="Button" /></div> </form> </body> </html>
SupHandler.ashx 用於獲取供應商資訊
<%@ WebHandler Language="VB" Class="SupHandler" %> Imports System Imports System.Web Imports System.Data.OracleClient Imports YuanHang.DBUtility Public Class SupHandler : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest context.Response.ContentType = "text/plain" Dim ssql As String = "SELECT cid,cname,caccount,cbank,caddress,cpostcode,cplace,ctype,cmode FROM T_FFY_CREDITBENEFICIARY" Dim dr As OracleDataReader = DbHelperSQL.ExecuteReader(ssql) Dim st As StringBuilder = New StringBuilder() While dr.Read() st.Append("<option value='" & dr("cid").ToString() & "'>" & _ dr("cname").ToString() & "</option>/n") End While dr.Close() context.Response.Write(st.ToString()) End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Class
PayModeHandler.ashx 用於獲取付款方式資訊
關於獲取下拉框值,如下: 供應商: Request.Form("DropDownList1") 付款方式: Request.Form("DropDownList2") OVER!!!<%@ WebHandler Language="VB" Class="PayModeHandler" %> Imports System Imports System.Web Imports System.Data.OracleClient Imports YuanHang.DBUtility Public Class PayModeHandler : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest context.Response.ContentType = "text/plain" context.Response.Clear() Dim strSupCode As String = context.Request.Form("supCode").ToString() Dim ssql As StringBuilder = New StringBuilder() If strSupCode <> "" Then ssql.Append(" SELECT * FROM (") ssql.Append(" SELECT 0 AS tag,ctype FROM T_FFY_CREDITBENEFICIARY") ssql.Append(" WHERE cid = '" & strSupCode & "'") ssql.Append(" UNION") ssql.Append(" SELECT 1 AS tag,ctype FROM T_FFY_CREDITBENEFICIARY") ssql.Append(" WHERE cid <> '" & strSupCode & "'") ssql.Append(" ) ORDER BY tag") Else ssql.Append(" SELECT distinct ctype FROM T_FFY_CREDITBENEFICIARY") End If Dim dr As OracleDataReader = DbHelperSQL.ExecuteReader(ssql.ToString()) Dim st As StringBuilder = New StringBuilder() While dr.Read() st.Append("<option value='" & dr("ctype").ToString() & "'>" & _ dr("ctype").ToString() & "</option>/n") End While dr.Close() context.Response.Write(st.ToString()) End Sub Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Class