有谁知道为什么此 SharePoint 代码返回 Null?
我不断收到“值不能为空”。我尝试过改变几件事,但找不到任何帮助。
List<int> selecteditems = new List<int>();
int itemnum = 0;
double totalsiteitems1 = (Double)ViewState["NoFiles"];
for (int i = 1; i <= totalsiteitems1; i++)
{
itemnum = Int32.Parse(Request.Form["option" + i]);
selecteditems.Add(itemnum);
}
foreach (int pubitem in selecteditems)
{
SPSite oSite = new SPSite(site);
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists[list];
SPListItem oListItem = oList.Items.GetItemById(pubitem);
oListItem["_ModerationStatus"] = 0;
oListItem.Update();
}
I keep getting a "Value cannot be null." Ive tried changing several things but just cant figure it out any help.
List<int> selecteditems = new List<int>();
int itemnum = 0;
double totalsiteitems1 = (Double)ViewState["NoFiles"];
for (int i = 1; i <= totalsiteitems1; i++)
{
itemnum = Int32.Parse(Request.Form["option" + i]);
selecteditems.Add(itemnum);
}
foreach (int pubitem in selecteditems)
{
SPSite oSite = new SPSite(site);
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists[list];
SPListItem oListItem = oList.Items.GetItemById(pubitem);
oListItem["_ModerationStatus"] = 0;
oListItem.Update();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Request.Form["option" + i]
返回某些内容并且可以将其解析为整数。ViewState["NoFiles"]
返回某物。
Request.Form["option" + i]
returns something and that it can be parsed to integer.ViewState["NoFiles"]
returnssomething.
我建议使用
TryParse
http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx" rel="nofollow">http:// /msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx
I would suggest using
TryParse
http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx