dept = Request.QueryString["JCid"].ToString();
sqlcmd = "select deptName from Dept where id = "+dept;
Label lb = (Label)DataList1.Items[0].FindControl("Label1");
lb.Text = service.GetValue(sqlcmd);程序这样代码上有错吗??莫非还要的html里面写代码?错误说是:“索引超出范围。必须为非负值并小于集合大小。参数名: index
”这个怎么回事??请赐教!!!
sqlcmd = "select deptName from Dept where id = "+dept;
Label lb = (Label)DataList1.Items[0].FindControl("Label1");
lb.Text = service.GetValue(sqlcmd);程序这样代码上有错吗??莫非还要的html里面写代码?错误说是:“索引超出范围。必须为非负值并小于集合大小。参数名: index
”这个怎么回事??请赐教!!!
解决方案 »
- 自动升级的原理
- DataGridView
- C#关于textBox的数据绑定的问题---有报错!
- 请问GDI+中对区域的填充是不是不能抗锯齿啊,多边形区域填充的边缘好难看。
- 求问,大型超市一般在18点到20点访问对数据库访问比较频繁
- 一个简单的存储过程
- 快急疯了,为什么Microsoft.Web.UI.WebControls.treeview 和 dropdownlist放在updatepanel里会刷整页
- 没有分了,请帮我看看
- using System.Messaging;出错:类型或命名空间名称“Messaging”在类或命名空间“System”
- 在VSS中的Check in和Check out 的问题
- 请如何实现在textbox中输入值后,,后动态在listbox中过滤出所需项目?
- 如何得到select 1的返回结果
----------------------------------------------------------------------
如果报出这种错误,一般都是Label lb = (Label)DataList1.Items[0].FindControl("Label1");
中Items[0]的0有问题,你的sqlcmd = "select deptName from Dept where id = "+dept;的记录是不是只有一行,如果大于一行,肯定回出现问题的,比如有两行的话,你这里怎么只可以写0呢
你这样写试试
sqlcmd = "select deptName from Dept where id = "+dept;
DataSet ds=new DataSet();
ds=Info.Select(sqlcmd,"Dept ");
if(ds.Table["Dept "].Rows.Count>0)
{
for(int j=0;j<ds.Table["Dept "].Rows.Count;j++)
{
Label lb = (Label)DataList1.Items[0].FindControl("Label1");
lb.Text = service.GetValue(sqlcmd);
}
}
这样写不管是0行还是多行都没有问题