<asp:DropDownList id="ddlclass" runat="server" Width=200 
        onChange="clange_class(document.Form1.ddlclass.options[document.Form1.ddlclass.selectedIndex].value)" AutoPostBack=true></asp:DropDownList>
        &nbsp;&nbsp;小类:<asp:DropDownList id="ddlitem" runat="server" Width="200px"></asp:DropDownList>protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WriteScript();
            bind_class();
            bind_item();
        }
    }在点解ie的刷新按钮后,DropDownList没有选项了

解决方案 »

  1.   

    bind_item();
    这个方法是绑定dropdownlist的方法吗?
    没有联动吧?
      

  2.   

    联动在页面用javascript做的,和那个没有关系 void bind_class()
        {
            ddlclass.DataSource = db_query.OpenQuery("select ClassID, CLassName from tb_class");
            ddlclass.DataValueField = "ClassID";
            ddlclass.DataTextField = "ClassName";
            ddlclass.DataBind();
        }    void bind_item()
        {
            if (ddlclass.SelectedItem == null)
            {
                return;
            }        ddlitem.DataSource = db_query.OpenQuery("select ID, ItemName from tb_item where ClassID=" + Convert.ToUInt32(ddlclass.SelectedValue));
            ddlitem.DataValueField = "ID";
            ddlitem.DataTextField = "ItemName";
            ddlitem.DataBind();
        }
      

  3.   

    绑定下拉控件的方法不要放在里面。          if (!IsPostBack)
            {
                WriteScript();
                bind_class();
                bind_item();
            }
      

  4.   

    你哪个droplist没有了选项?
      

  5.   

    ddlclass  这个还有吧
    ddlitem 这个没了?
    为什么不用调试看一下    ddlclass.SelectedValue 的值呢?
      

  6.   

    检查页面操作dropdownlist
    是否删除了
      <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                   <asp:DropDownList ID="ddl" runat="server" Width="15%" AutoPostBack="True" OnSelectedIndexChanged="ddl_SelectedIndexChanged">
                   </asp:DropDownList>
                     <asp:DropDownList ID="ddlChild" runat="server" Width="20%">
                   </asp:DropDownList>
                     </ContentTemplate>
            </asp:UpdatePanel>
            </div> 
      

  7.   

    在,页面加载 里.onload在再一段javascript<script>
    clange_class(document.Form1.ddlclass.options[document.Form1.ddlclass.selectedIndex].value);
    </script>放在你页面最底下。
      

  8.   

    page_load执行了两次被刷掉了吗
      

  9.   

    dropdownlist的enableviewstate不能设置为false
      

  10.   

    放在page_load的事件里,像这样bind_item();
    if (!IsPostBack)
            {
                WriteScript();
                bind_class();
            }
    我不知道你哪个方法是绑定下拉框的,估计是bind_item()
      

  11.   


    那么你就必须自己写(网站里成千上万个)任何维系视图状态的代码。否则,就学asp编程或者asp.net mvc编程,不要学asp.net webform编程。
      

  12.   


     <tr>
            <td>
            大&nbsp;&nbsp;&nbsp;&nbsp;类:
            <asp:DropDownList id="ddlclass" runat="server" Width=200 
            onChange="clange_class(document.Form1.ddlclass.options[document.Form1.ddlclass.selectedIndex].value)" EnableViewState=true></asp:DropDownList>
            &nbsp;&nbsp;小&nbsp;&nbsp;&nbsp;&nbsp;类:<asp:DropDownList id="ddlitem" runat="server" Width="200px" EnableViewState=true></asp:DropDownList>
            </td>
        </tr>
    后台代码:
     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                WriteScript();
                bind_class();
                bind_item();
            }
        }    private void WriteScript()
        {
            string str_sql = "select * from tb_item";
            string scriptString = get_class_change_script(str_sql, "ItemName", "ID", "ClassID", ddlitem.ID);        if (!ClientScript.IsClientScriptBlockRegistered("clientScript"))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", scriptString);
            }
        }    void bind_class()
        {
            this.ddlclass.DataSource = db_query.OpenQuery("select ClassID, CLassName from tb_class");
            this.ddlclass.DataValueField = "ClassID";
            this.ddlclass.DataTextField = "ClassName";
            this.ddlclass.DataBind();
        }    void bind_item()
        {
            if (this.ddlclass.SelectedItem == null)
            {
                return;
            }        this.ddlitem.DataSource = db_query.OpenQuery("select ID, ItemName from 
    tb_item where ClassID=" + Convert.ToUInt32(ddlclass.SelectedValue));
            this.ddlitem.DataValueField = "ID";
            this.ddlitem.DataTextField = "ItemName";
            this.ddlitem.DataBind();
        }
    public static string get_class_change_script(string str_sql, string x_c_str, string x_c_id, string d_c_id, string x_id_name)
        {
            int count = 0;
            string scriptString = "<Script Language=JavaScript>\n var onecount;";
            scriptString += "\n onecount=0;";
            scriptString += "\n subcat=new Array();";        DataTable dt = db_query.OpenQuery(str_sql);        for (int i = 0; i < dt.Rows.Count; ++i)
            {
                scriptString += "\n subcat[" + count + "]=new Array(" + "'" + dt.Rows[i][x_c_str] + "'" + "," + "'"
                    + dt.Rows[i][d_c_id] + "'" + "," + "'" + dt.Rows[i][x_c_id] + "'" + ");";
                count++;
            }        scriptString += "\n onecount=" + count + ";";
            scriptString += "\n function clange_class(class_id){";
            scriptString += "\n document.Form1." + x_id_name + ".length = 0;";
            scriptString += "\n var class_id=class_id;";
            scriptString += "\n var i;";
            scriptString += "\n for(i=0; i<onecount; i++){";
            scriptString += "\n if(subcat[i][1]==class_id){";
            scriptString += "\n document.Form1." + x_id_name + ".options[document.Form1." + x_id_name + ".length]=new Option(subcat[i][0],subcat[i][2]);";
            scriptString += "\n }";
            scriptString += "\n }";
            scriptString += "\n }";
            scriptString += "</script>";        return scriptString;
        }刷新的问题解决,主要是在vs2008的测试服务器不可以,is中可以。
    现在主要是提交的时候报错,各位帮忙,分不够再加
      

  13.   

    把数据绑定的 实现 写在 !IsPostBack 外面
      

  14.   

    这个是可以选的,如果放在!IsPostBack 外面,提交的时候有问题吧?
    各位高手帮帮忙