“gradeid”有一个无效 SelectedValue,因为它不在项目列表中 参数名: value

luojiankeji 2012-10-13 02:01:40
protected void Button2_Click(object sender, EventArgs e)
{
this.etime.Text = Convert.ToDateTime(this.btime.Text).AddMinutes(45).ToString();
}
protected void band_nj()
{
SqlConnection conn = Sqlcon.openDatabase();
string cmdtext = "select * from T_grade ";
SqlDataAdapter da = new SqlDataAdapter(cmdtext, conn);
DataSet ds = new DataSet();
da.Fill(ds);
this.gradeid.DataSource = ds;
this.gradeid.DataTextField = "gradename";
this.gradeid.DataValueField = "id";
this.gradeid.DataBind();//
ListItem item = new ListItem();
item.Text = "---请选择年级---";
item.Value = "-1";
this.gradeid.Items.Insert(0, item);
conn.Close();
conn.Dispose();


}
...全文
265 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2012-10-13
  • 打赏
  • 举报
回复
你应该有其他代码设置
this.gradeid.SelectedValue="xx"了吧?这样的语句是错误的
暖枫无敌 2012-10-13
  • 打赏
  • 举报
回复
代码看起来没什么问题,问题是你的数据有问题

自己检查下:
是不是某个T_grade 下并没有任何的T_class

luojiankeji 2012-10-13
  • 打赏
  • 举报
回复
CS文件代码
    protected void Button2_Click(object sender, EventArgs e)
{
this.etime.Text = Convert.ToDateTime(this.btime.Text).AddMinutes(45).ToString();
}
protected void band_nj()
{
SqlConnection conn = Sqlcon.openDatabase();
string cmdtext = "select * from T_grade ";
SqlDataAdapter da = new SqlDataAdapter(cmdtext, conn);
DataSet ds = new DataSet();
da.Fill(ds);
this.gradeid.DataSource = ds;
this.gradeid.DataTextField = "gradename";
this.gradeid.DataValueField = "id";
this.gradeid.DataBind();//
ListItem item = new ListItem();
item.Text = "---请选择年级---";
item.Value = "-1";
this.gradeid.Items.Insert(0, item);
conn.Close();
conn.Dispose();


}
protected void band_bj1(string gradeid)
{
SqlConnection conn = Sqlcon.openDatabase();
string cmdtext = "select * from T_class where gradeid='" + gradeid + "'";
SqlDataAdapter da = new SqlDataAdapter(cmdtext, conn);
DataSet ds = new DataSet();
da.Fill(ds);
this.classid.DataSource = ds;
this.classid.DataTextField = "classname";
this.classid.DataValueField = "id";
this.classid.DataBind();//
ListItem item = new ListItem();
item.Text = "---请选择年级---";
item.Value = "-1";
this.gradeid.Items.Insert(0, item);
conn.Close();
conn.Dispose();
}

protected void Dradeid_SelectedIndexChanged(object sender, EventArgs e)
{
string bigid = this.gradeid.SelectedValue.Trim();
band_bj1(bigid);
}
}
luojiankeji 2012-10-13
  • 打赏
  • 举报
回复
aspx文件中控件代码
                    当班投票的班级和年级:
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="gradeid" runat="server"
OnSelectedIndexChanged="Dradeid_SelectedIndexChanged" AutoPostBack="True">
</asp:DropDownList>
<asp:DropDownList ID="classid" runat="server">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
暖枫无敌 2012-10-13
  • 打赏
  • 举报
回复
“gradeid”有一个无效 SelectedValue,因为它不在项目列表中

出错的地方并不在你贴出来的这些代码中,请贴你设置选中项的那段代码先。
风之影子 2012-10-13
  • 打赏
  • 举报
回复
设断点,单步调试一下。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧