我想实现的是用select的onchange事件实现将数据库中的数据填充到select中急啊

解决方案 »

  1.   

    可能只能有ajax才能实现,谁知道怎么实现啊
      

  2.   

    用updateplane或者js的AJAX都可以实现
      

  3.   

    我现在不知道怎样用ajax+js实现呢?谁知道说下啊
      

  4.   

    方法很多种:
    1:ajax 异步返回Json数组。再绑定到select
    2:页面存在一个
    <select id="sle1" name="sle2">
     sle1Value</option>
    </select>
    异步找到页面v对象,后台添加好值如下:
    <option value=1>test</option>
    <option value=2>test1</option>
    覆盖sle1value对象,这种方法谨慎使用,因为页面不能存在多个相同的sle1Value对象否则都会覆盖。
      

  5.   

    异步找到页面sle1Value对象  ,,打错了。
      

  6.   

    后臺代碼:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;public partial class Default3 : System.Web.UI.Page
    {
        public string[] num = new string[10];
        protected void Page_Load(object sender, EventArgs e)
        {       getnumber();
        }
        public void  getnumber()
        {
            string[] arr = null;
            string constring = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();
            using (SqlConnection con = new SqlConnection(constring))
            {
                SqlDataAdapter da = new SqlDataAdapter("select top 10 number,chinesename,technical from employees", con);
                DataTable dt = new DataTable();
                da.Fill(dt);
                
                List<string> listnumber=new List<string>();
                
                 foreach(DataRow dr in dt.Rows)
                 {
                     listnumber.Add(dr[0].ToString());
                 }
                 num = listnumber.ToArray();
              
            }
        }
        class NumberOrder
        {
            private string number;
            public NumberOrder(string num)
            {
                number = num;
            }
        }
    }
    前臺代碼:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %><!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>
    <link rel="stylesheet" href="jquery-ui-1.8.16.custom/development-bundle/themes/base/jquery.ui.all.css">
    <script src="jquery-ui-1.8.16.custom/development-bundle/jquery-1.6.2.js"></script>
        <script src="jquery-ui-1.8.16.custom/development-bundle/jquery-1.6.2.js" type="text/javascript"></script>
    <script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.core.js"></script>
    <script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.widget.js"></script>
    <script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.position.js"></script>
    <script src="jquery-ui-1.8.16.custom/development-bundle/ui/jquery.ui.autocomplete.js"></script>
    <link rel="stylesheet" href="../demos.css">
    <script>
        $(function () {
            //         var availableTags = [
            // "ActionScript",
            // "AppleScript",
            // "Asp",
            // "BASIC",
            // "C",
            // "C++",
            // "Clojure",
            // "COBOL",
            // "ColdFusion",
            // "Erlang",
            // "Fortran",
            // "Groovy",
            // "Haskell",
            // "Java",
            // "JavaScript",
            // "Lisp",
            // "Perl",
            // "PHP",
            // "Python",
            // "Ruby",
            // "Scala",
            // "Scheme"
            // //];            ///以下是關鍵
            var availableTags = new Array();
                <% for(int i=0;i<10;i++) {%>
                //將數組中的數據賦于給js中數組中;
                availableTags.push('<%=num[i]%>');
                <%} %>
         
            $("#TextBox1").autocomplete({
                source: availableTags
            });
        });
    </script>
    </head>
    <body>
    <form runat="server">
    <div class="demo"><div class="ui-widget">
    <label for="tags">Tags: </label>
    <input id="tags" />
    </div>
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div></div><!-- End demo -->
    </form>
    </body>
    </html>
    運行此代碼此先到jquery中下載jquery-ui-1.8.16.custom