Click here to Skip to main content
15,887,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want update a value in my database based on a selection that was made in a GridView. The GridView has information on it and a checkbox that I use to update the corresponding value to the checkbox. The GridView has images that are returned using the business logic layer and we don't configure the gridview with an object datasource but we do it with code.

Below is the code that I use to update using the business logic layer

C#
protected void Page_Load(object sender, EventArgs e)
       {
           Business_Logic.Ballot objc = new Business_Logic.Ballot();
           GridView1.DataSource = objc.CandidateInfo();
           GridView1.DataBind();
       }
protected void btnsubmit_Click(object sender, EventArgs e)
       {


           for (int i = 0; i < GridView1.Rows.Count; i++)
           {
               CheckBox chkselect = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkselect");
               if (chkselect != null)
               {
                   if (chkselect.Checked)
                   {
                       string  idca = GridView1.Rows[i].Cells[0].Text;
                       {
                           Business_Logic.CastVote objc = new Business_Logic.CastVote();
                           objc.candidate_id =Convert .ToInt32( idca);
                           objc.SubmitBallot();
                       }
                   }
               }
           }


C#
namespace Business_Logic
{
    public class CastVote
    {
        public Int32 candidate_id { get; set; }
        public string username { get; set; }
        public string date { get; set; }

        public CastVote()
        {
            candidate_id = 0;
            username = string.Empty;
            date = string.Empty;
        }

        public CastVote(Int32 _cast, string _username, string _date)
        {
            candidate_id = _cast;
            username = _username;
            date = _date;
        }

        public void SubmitBallot()
        {
            csDAL objdal = new csDAL();
            List<csparameterlisttype> objlist = new List<csparameterlisttype>();
            objlist.Add(new csParameterListType("@candidate_id", System.Data.SqlDbType.Int, candidate_id));
            objlist.Add(new csParameterListType("@Usernames", System.Data.SqlDbType.Char, username));
            objlist.Add(new csParameterListType("@standingyear", System.Data.SqlDbType.VarChar, date));
            objdal.executespreturnnd("update_total", objlist);
        }
    }
}
</csparameterlisttype></csparameterlisttype>


Edit: Removed Text Formatting.
Posted
Updated 6-Oct-11 12:44pm
v2

1 solution

Just a guess, but does the SP require valid @Usernames and @standingyear parameters? You're not setting the properties on your objc object.
 
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