Home > Forum > C# > Load boolean value for selected row from gridview to checkbox

Load boolean value for selected row from gridview to checkbox

by DWAYNE PRATT   on Oct 25, 2014   Category: C#  |  Views: 1249    |  Points: 5   |  Starter 
  Reply
i have a gridview attached to a datasource. i would like to load the selected row into on page controls. the textbox box works fine however I am having dificultly loading the checkbox.

sample

protected void gvAgentTrainingDetails_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = gvAgentTrainingDetails.SelectedRow;

txtAgentNo.Text = row.Cells[1].Text;
txtTraineeName.Text = row.Cells[4].Text;

}

how do i get the value into a check box. the database value is bit

Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :Load boolean value for selected row from gridview to checkbox   
by Thamil
on Oct 26 2014 2:06AM
Points : 10
Gold 
Hi DWAYNE PRATT ,
Please try with below code.
protected void gvAgentTrainingDetails_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = gvAgentTrainingDetails.SelectedRow;
txtAgentNo.Text = row.Cells[1].Text;
txtTraineeName.Text = row.Cells[4].Text;
string strActive = row.Cells[5].Text; //Assume cell # 5 return as Boolean value
if (strActive == "true")
{
chkActive.Checked =true;
}
else
{
chkActive.Checked =false;
}

}

Recent Post

Latest Posts