我正在使用复选框更新整数值. [英] I'm updating an integer value with a checkbox.
本文介绍了我正在使用复选框更新整数值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这段代码来尝试使用复选框更新数据库中的整数值.当我使用类的对象调用更新方法时,它在按钮后面的代码上给了我一个错误
I''m having this code seeking to update an integer value on database using a checkbox. it give me an error on code behind the button when i use the object of class to call the update method
//this is my my business logic
public class CastVote
{
public Int32 id { get; set; }
public Int32 [] cast { get; set; }
public CastVote()
{
id=0;
cast=null;
}
public CastVote(Int32 _id, int [] _cast)
{
id = _id;
cast = _cast;
}
public void Votes(Int32 id)
{
csDAL objdal = new csDAL();
List<csParameterListType> objlist = new List<csParameterListType>();
objlist.Add(new csParameterListType("@id", System.Data.SqlDbType.Int, id));
objdal.executespreturnnd("cast_vote", objlist);
}
}
//code behind the button
StringCollection idCollection = new StringCollection();
string strid = string .Empty ;
//loop through gridview to find checked rows
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chckupdate = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chckhere");
if (chckupdate != null)
{
if (chckupdate.Checked)
{
strid = GridView1.Rows[i].Cells[1].Text;
idCollection.Add(strid);
}
}
}
if (idCollection.Count >= 0)
{
BLL.CastVote obj = new CastVote();
obj.id = Convert.ToInt32(idCollection.Count);
obj.Votes();
//it give an error here
}
else
{
//lblmsg.Text = "Please select your favourate candidates";
}
}
推荐答案
obj.id = Convert.ToInt32(idCollection.Count);
Convert.ToInt32是不必要的,因为StringCollection或任何集合的Count属性已经是整数.
您需要缩小一点,抛出的异常是什么?
The Convert.ToInt32 is unnecessary since the Count property of the StringCollection, or any collection, is already an integer.
You need to narrow it down a bit, what is the exception that is being thrown?
这篇关于我正在使用复选框更新整数值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文