我在页面添加了一个DropDownList控间,ID为DropDownList1
然后在CS中的PAGE_LOAD中给他赋值,当选择下拉框的时候出发DropDownList1_SelectedIndexChanged的方法,现在的问题是根本在选择下拉框的时候根本没有出发DropDownList1_SelectedIndexChanged的方法,后来我就把PAGLE_LOAD里的赋值代码给去掉了,在ASPX中给DropDownList1赋值,结果就可以触发DropDownList1_SelectedIndexChanged方法,请问这怎么解决,真的很头痛
下面是代码
ASPX:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>CS:
  protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
       {
            for (int i = 10; i <= 100; i += 10)
            {
                ListItem ls = new ListItem();
                ls.Text = i.ToString() + "人";
                ls.Value = i.ToString();
                DropDownList1.Items.Add(ls);
            }
            DropDownList1.Items.Add(new ListItem("全部", ""));
            DropDownList1.SelectedValue = "";
           // DropDownList2.Items.Add(new ListItem("--", ""));
       }
    }
 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
            for (int i = 10; i <= 100; i += 10)
            {
                ListItem ls = new ListItem();
                ls.Text = i.ToString() + "人";
                ls.Value = i.ToString();
                DropDownList2.Items.Add(ls);
            }
            DropDownList2.Items.Add(new ListItem("全部", ""));
            DropDownList2.SelectedValue = "";
    }

解决方案 »

  1.   

    你这2个方法里内容都一样啊,你看看把他写成jscript吧
      

  2.   

    转到设计页面,选中DropDownList控件,在查看属性,点击闪电形状的事件按钮,将OnSelectedIndexChanged事件绑定到DropDownList1_SelectedIndexChanged
      

  3.   

    1、Aspx中去掉 OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
    2、在DropDownList1_SelectedIndexChanged中添加断点跟踪,我这儿测试没有问题
      

  4.   

    huo789(四火)
    我去掉了OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
    还是不能执行
      

  5.   

    wzq6511(给偶点分分) 
    已经是绑定的
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
    </asp:DropDownList>
    这都写进去了呢
      

  6.   

    huo789(四火)
    去掉了OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
    这就没有绑定了,这肯定是不行的
      

  7.   

    DropDownList1_SelectedIndexChanged如果是在脚本里面写的你这样可以,如果在cs中写的还要到事件里面绑定。你先按我说的试下,不行在说。
      

  8.   

    把 DropDownList1.SelectedValue = "";
    改成 DropDownList1.SelectedIndex = -1;
      

  9.   

    yx10(杨过) 
    把 DropDownList1.SelectedValue = "";
    改成 DropDownList1.SelectedIndex = -1;
    这个只是个默认值而已,改了没有用
      

  10.   

    我的问题是选择下拉框的时候根本没有调用DropDownList1_SelectedIndexChanged方法
    而且选择后,下拉框什么东西都没有
      

  11.   

    你把ASPX的代码和cs的代码都贴出来,我帮你整整看
      

  12.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="BusiAccount.aspx.cs" Inherits="BusiAccount" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        <title>商户录入</title>
        <link href="images/css.css" rel="stylesheet" type="text/css" />
    </head><body style="text-align: center">
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td width="10" height="658" valign="top" background="images/test_r2_c3.gif">
                </td>
                <td valign="top" bgcolor="#FFFFFF">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td width="1%">
                                <img src="images/middle_1.gif" width="11" height="31"></td>
                            <td width="98%" background="images/middle_2.gif" class="title">
                                &nbsp;</td>
                            <td width="1%">
                                <img src="images/middle_3.gif" width="11" height="31"></td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#BAD0EC">
                                    <tr>
                                        <td height="625" valign="top" bgcolor="#FFFFFF">
                                            <asp:Label ID="Label1" runat="server"></asp:Label>
                                            <br />
                                            <form id="frmPost" method="post" runat="server">
                                                <table width="90%" border="0" align="center" cellpadding="5" cellspacing="1" class="mytable">
                                                    <tbody>
                                                        <tr>
                                                            <td align="right" bgcolor="#ffffff">
                                                                公司全称:</td>
                                                            <td height="20" align="left" bgcolor="#ffffff">
                                                                <asp:DropDownList ID="DropDownList1" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"  runat="server">
                                                               <%--<asp:ListItem Value ="1">1</asp:ListItem>
                                                                <asp:ListItem Value ="2">2</asp:ListItem>
                                                                <asp:ListItem Value ="3">3</asp:ListItem>
                                                                <asp:ListItem Value ="4">4</asp:ListItem>--%>
                                                                </asp:DropDownList></td>
                                                            <td align="right" bgcolor="#ffffff">
                                                                公司全称:</td>
                                                            <td height="20" align="left" bgcolor="#ffffff">
                                                                <asp:DropDownList ID="DropDownList2" runat="server"  AutoPostBack="True">
                                                                </asp:DropDownList></td>
                                                        </tr>
     
                                                    </tbody>
                                                </table>
                                                <br />
                                            </form>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
                <td width="7" valign="top" background="images/test_r3_c5.gif" bgcolor="#EEF3FA">
                </td>
            </tr>
            <tr>
                <td width="10">
                    <img name="test_r5_c3" src="images/test_r5_c3.gif" width="10" height="25" border="0"
                        id="test_r5_c3" alt="" /></td>
                <td background="images/test_r5_c4.gif">
                    &nbsp;</td>
                <td>
                    <img name="test_r5_c5" src="images/test_r5_c5.gif" width="7" height="25" border="0"
                        id="test_r5_c5" alt="" /></td>
            </tr>
        </table>
    </body>
    </html>
      

  13.   

    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;
    using System.Data.OleDb;
    using LongSun.Platform.Helper;
    using LongSun.Platform.Util.Page;
    using LongSun.Platform.Util.FacePage;
    using LongSun.Platform.Tool.Web;public partial class BusiAccount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                if (!IsPostBack)
               {
                   for (int i = 10; i <= 100; i += 10)
                   {
                       DropDownList1.Items.Add(new ListItem(i.ToString()));
                   }
                   DropDownList1.Items.Add(new ListItem("全部", ""));
                   DropDownList1.SelectedValue = "";
                   DropDownList2.Items.Add(new ListItem("--", ""));
           }
        }
        //protected void Insert(object sender, EventArgs e)
        //{ 
        
        //}
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Write("aaaaaaaaaa");
            for (int i = 10; i <= 100; i += 10)
            {
                ListItem ls = new ListItem();
                ls.Text = i.ToString() + "人";
                ls.Value = i.ToString();
                DropDownList2.Items.Add(ls);
            }
            DropDownList2.Items.Add(new ListItem("全部", ""));
            DropDownList2.SelectedValue = "";
        }
        //protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        //{    //}
    }
      

  14.   

    protected void  provinceDropDown_Init(object sender, EventArgs e)
    {}
     在这个方法里面初始发就可以了
      

  15.   

    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion把上面这段加到你的代码里去。
    我这边完全可以。
      

  16.   

    把Page_load里的代码写成函数的形式,再调用函数。