读书人

DropDownList取不到值的有关问题

发布时间: 2013-12-23 14:30:52 作者: rapoo

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 了。

读书人网 >C#

热点推荐