日期:2014-05-17  浏览次数:20755 次

DropDownList取不到值的问题



    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList2.DataSource = new ProjectTypeServer().GetAll();
            DropDownList2.DataBind();
        }
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        
        if (DropDownList2.SelectedIndex == -1)
        {
            PageBase.alert(Page, "系统错误");
            return;
        }
}


页面上面是能够读取出来下拉框的,一点击按钮提交就报空值,出完错点确定之后下拉框就没有值了,我根踪调试了一下,发现点击按钮之后DropDownList2.Item.Count的值为0,这是何解?从来没有遇到过这样的问题

------解决方案--------------------
引用:



    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList2.DataSource = new ProjectTypeServer().GetAll();
            DropDownList2.DataBind();
        }
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        
        if (DropDownList2.SelectedIndex == -1)
        {
            PageBase.alert(Page, "系统错误");
            return;
        }
}


页面上面是能够读取出来下拉框的,一点击按钮提交就报空值,出完错点确定之后下拉框就没有值了,我根踪调试了一下,发现点击按钮之后DropDownList2.Item.Count的值为0,这是何解?从来没有遇到过这样的问题


检查一下是否设置 EnableViewstate 为 false 了。