zoukankan      html  css  js  c++  java
  • 一个简单的2级连动(实际都写烂了,做项目顺便写了一个,可能还有些不完善)

    //作者:崔宏宇
    //时间:2007-06-06
    //说明:用AjaxPro.2.dll框架
    Web.Config中配置
    <?xml version="1.0"?>
    <!--
        Note: As an alternative to hand editing this file you can use the
        web admin tool to configure settings for your application. Use
        the Website->Asp.Net Configuration option in Visual Studio.
        A full list of settings and comments can be found in
        machine.config.comments usually located in
        \Windows\Microsoft.Net\Framework\v2.x\Config
    -->
    <configuration>
      <appSettings/>
      <connectionStrings>
      </connectionStrings>
      <system.web>
        <httpRuntime maxRequestLength="10240"  executionTimeout="600"/>
        <!--
                Set compilation debug="true" to insert debugging
                symbols into the compiled page. Because this
                affects performance, set this value to true only
                during development.
            -->
        <compilation debug="true"/>
        <!--
                The <authentication> section enables configuration
                of the security authentication mode used by
                ASP.NET to identify an incoming user.
            -->
        <authentication mode="Windows"/>
        <!--
                The <customErrors> section enables configuration
                of what to do if/when an unhandled error occurs
                during the execution of a request. Specifically,
                it enables developers to configure html error pages
                to be displayed in place of a error stack trace.

            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
        <httpHandlers>
          <add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
        </httpHandlers>
      </system.web>
      <location path="ajaxpro">
        <system.web>
          <httpHandlers>
            <add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
          </httpHandlers>
          <!--
        If you need to have Ajax.NET Professional methods running on the
        login page you may have to enable your own authorization configuration
        here.
       -->
          <!--
       <authorization>
        <deny users="?"/>
       </authorization>
       -->
        </system.web>
      </location>
    </configuration>
    前台代码:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Example.aspx.cs" Inherits="Example" %>

    <!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 language="javascript">
        function Getsting()
    {
    debugger;
    var DropDownList1= document.getElementById("DropDownList1");
    var DropDownList2= document.getElementById("DropDownList2");
    var ExampleDT=Example.MyLight(DropDownList1.value);
    //删除DropDownList2
    DropDownList2.options.length=0;
            for(var i = 0; i < ExampleDT.value.Rows.length; i++)
        {
                DropDownList2.options.add(new Option(ExampleDT.value.Rows[i]["one"],ExampleDT.value.Rows[i]["two"])); 
                DropDownList2.selectedIndex=0;
        }
    }
     </script>
                           
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="DropDownList1" runat="server" onchange="Getsting()">
            <asp:ListItem Value="1">第一</asp:ListItem>
            <asp:ListItem Value="2">第二</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList2" runat="server">
            </asp:DropDownList>
        </div>
        </form>
    </body>
    </html>
    后台代码:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class Example : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(Example));
        }
        [AjaxPro.AjaxMethod]
        public DataTable MyLight(string Mycondition)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("one");//添加一列,想加几列再自己加
            dt.Columns.Add("two");
            DataRow dr;
            if (Mycondition == "1")
            {
                for (int i = 0; i < 10; i++)//每列添多少行,条件自己加
                {
                    dr = dt.NewRow();
                    dr["one"] = "" + i + "第一列";
                    dr["two"] = "" + i + "第二列";
                    dt.Rows.Add(dr);//添加一行
                }
            }
            else if (Mycondition == "2")
            {
                for (int i = 0; i < 10; i++)//每列添多少行,条件自己加
                {
                    dr = dt.NewRow();
                    dr["one"] = "" + i + "换第一列";
                    dr["two"] = "" + i + "换第二列";
                    dt.Rows.Add(dr);//添加一行
                }
            }

            return dt;
        }
    }

  • 相关阅读:
    机器学习:贝叶斯分类器(一)——朴素贝叶斯分类器
    机器学习:kNN算法(二)—— 实战:改进约会网站的配对效果
    机器学习:kNN算法(一)—— 原理与代码实现(不调用库)
    Oracle给表设置自增字段
    IMAP、POP3、SMTP邮件服务器
    网站高并发大流量访问的10个处理及解决方案
    浅谈async/await
    【前端】加载的图片太多或者太大优化方案(上)
    【前端】本地调试H5页面方案总结
    alphafold2_conda版安装
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/773188.html
Copyright © 2011-2022 走看看