Click here to Skip to main content
16,004,924 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
//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);
       }
    }

C#
//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";
                }
            }
Posted
Updated 24-Aug-11 1:51am
v3
Comments
[no name] 24-Aug-11 7:53am    
What error?
Timberbird 24-Aug-11 7:56am    
What kind of error does it give you? What does your SP "cast_vote" declaration look like?

1 solution

obj.id = Convert.ToInt32(idCollection.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?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900