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.