陋室铭
永远也不要停下学习的脚步(大道至简至易)

//作者:崔宏宇
//时间: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;
    }
}

 

 

posted on 2007-06-06 10:27  宏宇  阅读(422)  评论(0编辑  收藏  举报