Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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();
            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();
                        }
                    }
                }
            }                                                
 
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 6-Oct-11 5:43am
Edited 6-Oct-11 12:44pm
v2

1 solution

Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 383
1 Richard Deeming 180
2 ChauhanAjay 176
3 Sergey Alexandrovich Kryukov 171
4 Yogesh Kumar Tyagi 165
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 6 Oct 2011
Copyright © CodeProject, 1999-2014
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