VoteCount = io.GetVoteCount();
判断下VoteCount的值

解决方案 »

  1.   

    在Page_Load里的时候VoteCount的值是正确的,不过到了前台调用后台的时候VoteCount的值就变为0了,不知道为什么啊,郁闷。...
      

  2.   

    private int VoteCount;改为protected int VoteCount;
      

  3.   

    我好象试过了,即使改成public也是一样啊,还有别的方法吗?
      

  4.   

    把Image2中对width的赋值写在cs的pageload里VoteCount = io.GetVoteCount();之后!!!只能这样改,错误原因是VoteCount没被赋值时就被使用了;
      

  5.   

    没有别的办法了吗,因为这是个GridView中的ItemTemple列中的Image,本来是绑定的时候自动计算每个选项的Width
      

  6.   

    那你试试在VoteCount赋值之后绑定GridView!没用过VS2005,绑定它的时候像DataGRid一样有itemcreate事件吗?如果有,则可以在那里面写
      

  7.   

    你可以直接判断一下你的VoteCount
    在试试看!!
      

  8.   


      最好的解决办法就是把计算好每一行所对应的VoteCount值,把值放进你绑定GridView的数据表里面,然后给Width设置绑定字段。
      

  9.   

    private int VoteCount
    {
       get{return (int)ViewState["VoteCount"];}
       set{ViewState["VoteCount"] = value;}
    }改用属性 + ViewState处理.楼主应该再看下ASP.NET的运行机制..
      

  10.   

    include_me(丁一) ( ) 信誉:99 :他怎么说是未将对象引用到对象的实例呢,我把你的这段代码写在原来VoteCount的地方,请指教....
      

  11.   

    要在WEB页面使用的变量,建议用Viewstate
      

  12.   

    ItemOperation io=new ItemOperation();
    //获取总投票数
    VoteCount = io.GetVoteCount();这个地方有问题
      

  13.   

    用了ViewState怎么出现这个错误呢:
    System.NullReferenceException: 未将对象引用设置到对象的实例。
      

  14.   

    跟代码,看 Page_Load 中是否正确取回并设置 VoteCount
      

  15.   

    VoteView["VoteCount"]=io.GetVoteCount();
    Label1.Text=VoteView["VoteCount"].ToString();
    能运行这两句,结果也是正确的,但是从前台调用后台后就出现了那个问题,未将对象引用到实例,真的不知道会这样,我用Session也出现同样的问题
      

  16.   

    晕.. 晕.. 晕..下面这样写,再试
    ---------------------------------------
    private int VoteCount
    {
       get{return (int)ViewState["VoteCount"];}
       set{ViewState["VoteCount"] = value;}
    }private void Page_Load(object sender, System.EventArgs e)
    {
    ItemOperation io=new ItemOperation();
    //获取总投票数
    VoteCount = io.GetVoteCount();
    }public int FormatVoteCount(String itemCount)
    {
    return ((Int32.Parse(itemCount) * 100 / VoteCount));
    }
      

  17.   

    把 private int VoteCount;改为private static int VoteCount;