Click here to Skip to main content
12,955,493 members (62,129 online)
Rate this:
Please Sign up or sign in to vote.
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

 protected void Page_Load(object sender, EventArgs e)
            Business_Logic.Ballot objc = new Business_Logic.Ballot();
            GridView1.DataSource = objc.CandidateInfo();
 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);

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);

Edit: Removed Text Formatting.
Posted 6-Oct-11 5:43am
Updated 6-Oct-11 12:44pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just a guess, but does the SP require valid @Usernames and @standingyear parameters? You're not setting the properties on your objc object.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,719
CHill60 3,550
Maciej Los 3,153
ppolymorphe 2,060
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 6 Oct 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100