一个比较简单的问题,请进来帮下忙,就可以得到50分了,呵呵 VoteCount = io.GetVoteCount();判断下VoteCount的值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在Page_Load里的时候VoteCount的值是正确的,不过到了前台调用后台的时候VoteCount的值就变为0了,不知道为什么啊,郁闷。... private int VoteCount;改为protected int VoteCount; 我好象试过了,即使改成public也是一样啊,还有别的方法吗? 把Image2中对width的赋值写在cs的pageload里VoteCount = io.GetVoteCount();之后!!!只能这样改,错误原因是VoteCount没被赋值时就被使用了; 没有别的办法了吗,因为这是个GridView中的ItemTemple列中的Image,本来是绑定的时候自动计算每个选项的Width 那你试试在VoteCount赋值之后绑定GridView!没用过VS2005,绑定它的时候像DataGRid一样有itemcreate事件吗?如果有,则可以在那里面写 你可以直接判断一下你的VoteCount在试试看!! 最好的解决办法就是把计算好每一行所对应的VoteCount值,把值放进你绑定GridView的数据表里面,然后给Width设置绑定字段。 private int VoteCount{ get{return (int)ViewState["VoteCount"];} set{ViewState["VoteCount"] = value;}}改用属性 + ViewState处理.楼主应该再看下ASP.NET的运行机制.. include_me(丁一) ( ) 信誉:99 :他怎么说是未将对象引用到对象的实例呢,我把你的这段代码写在原来VoteCount的地方,请指教.... 要在WEB页面使用的变量,建议用Viewstate ItemOperation io=new ItemOperation();//获取总投票数VoteCount = io.GetVoteCount();这个地方有问题 用了ViewState怎么出现这个错误呢:System.NullReferenceException: 未将对象引用设置到对象的实例。 跟代码,看 Page_Load 中是否正确取回并设置 VoteCount VoteView["VoteCount"]=io.GetVoteCount();Label1.Text=VoteView["VoteCount"].ToString();能运行这两句,结果也是正确的,但是从前台调用后台后就出现了那个问题,未将对象引用到实例,真的不知道会这样,我用Session也出现同样的问题 晕.. 晕.. 晕..下面这样写,再试---------------------------------------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));} 把 private int VoteCount;改为private static int VoteCount; Repeater中的控件问题 怎样实现repeater控件的无限分级嵌套? 【求助】ling实现问题 ASP不用提交按钮怎样更新记录 帮帮忙 谢谢大家 关于ASP.NET的问题 急召.ASP.net程序员 我想要它循环显示! 求助 高分 vs2003下怎样部署asp.net程序 连接串到底要怎么写啊? 如何读取SQL server中的image类型数据 大家帮我看看这个web.config文件错在哪里? 投票系统显示不了多投票,不知怎么回事
在试试看!!
最好的解决办法就是把计算好每一行所对应的VoteCount值,把值放进你绑定GridView的数据表里面,然后给Width设置绑定字段。
{
get{return (int)ViewState["VoteCount"];}
set{ViewState["VoteCount"] = value;}
}改用属性 + ViewState处理.楼主应该再看下ASP.NET的运行机制..
//获取总投票数
VoteCount = io.GetVoteCount();这个地方有问题
System.NullReferenceException: 未将对象引用设置到对象的实例。
Label1.Text=VoteView["VoteCount"].ToString();
能运行这两句,结果也是正确的,但是从前台调用后台后就出现了那个问题,未将对象引用到实例,真的不知道会这样,我用Session也出现同样的问题
---------------------------------------
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));
}