make sure Session["Area"] is not null and AreaList does have index 1

解决方案 »

  1.   

    能否贴出出错信息?单从这句话来看同意【saucer(思归)】的说法。
      

  2.   

    E:\ASP.net程序\smallmuda\Unicom_1001\Admin_AddAdmin.aspx.cs(136): 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句136行 ddlArea.Items.IsReadOnly;
      

  3.   

    我也觉得是
    ddlArea.Items.IsReadOnly
    这个地方的事
      

  4.   

    这不,错误提示信息不已经说的很明白:136行 ddlArea.Items.IsReadOnly;//不能作为一个语句
                                   // 除了象:int i;i++, new someObject;等可以作为语句
    改为  ddlArea.Items.IsReadOnly=true;(或fasle);
      

  5.   

    这不,错误提示信息不已经说的很明白:136行 ddlArea.Items.IsReadOnly;//不能作为一个语句
                                   // 除了象:int i;i++, new someObject;等可以作为语句
    改为  ddlArea.Items.IsReadOnly=true;(或fasle);
      

  6.   

    那就把不需要的去掉ddlArea.Items.Remove();
      

  7.   

    那就把不需要的去掉ddlArea.Items.Remove(i);
    你是写了循环吧???
      

  8.   

    刚才的问题解决了,但我的if条件句里有出现了问题
    我把整段代码贴出来,谢谢各位。
    private void Bind_ddlArea()
    {

    string Sql="select id, Area from Area";
    Db List=new Db();
    OleDbDataReader AreaList=List.GetList(Sql);
    while (AreaList.Read())
    {
    ListItem ilist=new ListItem(AreaList.GetString(1));
    if ((string)Session["Area"].ToString().Trim()==AreaList.GetValue(1).ToString().Trim())
    {
    ilist.Selected=true;

    }
    ddlArea.Items.Add(ilist);
    }
    if ((string)Session["Area"].ToString().Trim()==AreaList.GetValue(1).ToString().Trim())
    {
    ddlArea.Items.IsReadOnly=true;
    }
    AreaList.Close();
    }我的目的就是当他是当地(area)的用户,就只能选当地(area)了
    不存在此行/列的数据。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 不存在此行/列的数据。我想就是AreaList.GetValue(1).ToString().Trim()没有这个值。
    那应该怎么取呢!?
      

  9.   

    lkk2073(三楼楼长) 
    ddlArea.Items.Remove(i);这样错了,
    E:\ASP.net程序\smallmuda\Unicom_1001\Admin_AddAdmin.aspx.cs(133): 与“System.Web.UI.WebControls.ListItemCollection.Remove(string)”最匹配的重载方法具有一些无效参数