get boolean value from selected row of datatable

282 views Asked by At

i am trying to select the bit value of sql which is present in the grid when trying to access its just giving error.

protected void ProductGrid_SelectedIndex(object sender, EventArgs e) { PRID.Text=RequisitionGrid.SelectedRow.Cells[1].Text;

        vid.Text=RequisitionGrid.SelectedRow.Cells[2].Text;

        vaddress.Text=RequisitionGrid.SelectedRow.Cells[3].Text;

        BrandID.Text=RequisitionGrid.SelectedRow.Cells[4].Text;

        prodID.Text=RequisitionGrid.SelectedRow.Cells[6].Text;

        quantity.Text=RequisitionGrid.SelectedRow.Cells[7].Text;

        description.Text=RequisitionGrid.SelectedRow.Cells[5].Text;

        date.Value = RequisitionGrid.SelectedRow.Cells[8].Text;
  approvecheck.Checked = Convert.ToBoolean(RequisitionGrid.SelectedRow.Cells[9]);             
    }

i also tried

approvecheck.Checked = (RequisitionGrid.SelectedRow.Cells[9].Text == "1");

it does not give error but yet no response to the checkbox

1

There are 1 answers

4
Jacob JA Shanks On

Try directly casting the cell to a bool instead of converting it.

approvecheck.Checked = ((bool)RequisitionGrid.SelectedRow.Cells[9]);