-1
I have a GridView
filling correctly, but I need to take the value of column 5, which is of type BIT
in the database (SQL Server).
In every way I try, informs error, I tried to pass to a variable of type bool
, move on to a CheckBox
and yet the error persists.
Follows the code:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
txtid.Text = (GridView1.SelectedRow.Cells[0].Text);
conta = (GridView1.SelectedRow.Cells[2].Text);
bool Insertar = ((CheckBox)(GridView1.SelectedRow.Cells[5].FindControl("quitado"))).Checked;
if (Insertar == true)
{
cbquitado.Checked = true;
}
}
I tried that way too:
bool quitado = Convert.ToBoolean(GridView1.SelectedRow.Cells[5].Text);
How can I get the value of the column by selecting the row in the GridView
?
I tried this way Ismael, and it occurred to me error in this line: cbquitado. Checked = Insert.Checked; Error: Undefined object reference for an instance of an object.
– Mariana
I was already editing the answer telling you to check first if the
SelectedRow
is or is not null. This property is only valid for when you click at least one line. It starts as null.– Ismael
rsrs I show the field in a message, but it comes null, only q with a normal string field in the same command, normal appears.
– Mariana
In his gridview he’s not the Checkboxfield type?
– Ismael
Exact. <Asp:Checkboxfield Datafield="quitado" Headertext="Quitado"> <Headerstyle Horizontalalign="Center" /> <Itemstyle Horizontalalign="Center" /> </Asp:Checkboxfield> I tried this way q informed me, and shows me the same error on the line: cbquitado. Checked = Insert.Checked. Error: Undefined object reference for an instance of an object.
– Mariana
I managed to solve Ismael by performing a select through the ID that I can get normally, and solved the problem, thank you very much.
– Mariana