是吗?
为什么当执行Page_Load(){}里的DropDownList1_SelectChange(null,null)时
为什么DropDownList1.SelectIndex 有时会等于 0  ,而不是我用 DropDownList1.SelectIndex = Convert.ToInt32(Request.Params["SelectIndex"]); 传过来的值?

解决方案 »

  1.   


    你的意思是根据传递过来的参数SelectIndex,来显示对应的DropDownList1中的值,对吧?
      

  2.   

    当然能解决了!把你的WebForm1.aspx和WebForm1.aspx.cs都贴出来,我看看
      

  3.   

    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体">
    <asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 294px; POSITION: absolute; TOP: 181px" runat="server" Width="209px" Height="23px" AutoPostBack="True">
    <asp:ListItem Value="0" Selected="True">0</asp:ListItem>
    <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></FONT> <span id="Info" runat="server"></span>
    </form>
    </body>
    </HTML>
    //********************************************************************************
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace WebApplication2
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
                      protected  int SelectIndex;
    protected System.Web.UI.WebControls.DropDownList DropDownList1;
        protected System.Web.UI.HtmlControls.HtmlGenericControl Info;
    private void Page_Load(object sender, System.EventArgs e)
    {
                          if(Request.Params["SelectIndex"]!=null)
                          {
                                  DropDownList1.SelectIndex = Convert.ToInt32(Request.Params["SelectIndex"]);//附值DropDownList1.SelectIndex
                                  DropDownList1_SelectChange(null,null);//关键这句。
                                  //当执行时它的DropDownList1.SelectIndex是不是上行                            //附的Request.Params["SelectIndex"]!值。
                                  //我的结果是,大多数是 ,有时为0。
                           }
    // 在此处放置用户代码以初始化页面
    }
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    Info.InnerHtml = "";
    Info.InnerHtml = DropDownList1.SelectedIndex.ToString();
                                SelectIndex = DropDownList1.SelectedIndex;
    Info.InnerHtml +="<A href =WebForm1.aspx?i="+SelectIndex+"><下一页></A>";
    }
    }
    }
      

  4.   

    TO: shitingzhao(淡淡一笑)  THANKS
      

  5.   

    你的程序的问题在于你的页面参数使用问题看看这样是不是你要的效果:WebForm1.aspx:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="aspnettest.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <script language=javascript>
    <!--
    function changeit()
    {
     var ddl = document.all.DropDownList1;
     var a = ddl.selectedIndex;
     
     var b = ddl.options.length;
     if(a == b-1)
     {
      if(confirm('已经到了DropDownList1的最后一项,重新开始?'))
      {
       ddl.selectedIndex = 0; 
       document.all.DropDownList1.onchange();
      }
     }
     else
     {
     ddl.selectedIndex = a + 1;
     document.all.DropDownList1.onchange();
     } 
    }
    //-->
    </script> </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:dropdownlist id="DropDownList1" style="Z-INDEX: 101; LEFT: 294px; POSITION: absolute; TOP: 181px"
    runat="server" AutoPostBack="True" Height="23px" Width="209px">
    <asp:ListItem Value="0" Selected="True">0</asp:ListItem>
    <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></FONT><span id="Info" runat="server"></span></form>
    </body>
    </HTML>
    WebForm1.aspx.cs:using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace aspnettest
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.HtmlControls.HtmlGenericControl Info;
    protected System.Web.UI.WebControls.DropDownList DropDownList1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!this.Page.IsPostBack)
    {
    DropDownList1_SelectedIndexChanged(null,null);
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    Info.InnerHtml = "";
    Info.InnerHtml = DropDownList1.SelectedIndex.ToString();
    int SelectIndex = DropDownList1.SelectedIndex;
    this.DropDownList1.SelectedIndex = SelectIndex;
    //Info.InnerHtml +="<A href = dropdownlist.aspx?i="+(SelectIndex+1)+"><下一页></A>";
    Info.InnerHtml += "<A href=javascript:changeit()><下一页></A>";
    }
    }
    }