Checkbox value in datagrid does not reflect appearance

P

PaulNaude

I have a datagrid with boolean columns and as a test I display the value of
the checkbox in a label (not bound) as the user clicks in the grid cell.
Depending on the value of the checkbox as set by the user, my code should go
different routes.

My problem is that the value of that particular cell stays the same
regardless of its visible appearance. Only when the user re-enters the cell
after selecting a different row, does the value reflect the actual visibly
set value. The value then changes again but referencing it as set out below
shows the value when the user entered the cell.

In the datagrid's click event I used:

Label1.Text +=
DataSet71.Tables("MyTable").DefaultView.Item(DataGrid1.CurrentRowIndex).Item(1).ToString

and also

Label1.Text += DataGrid1.Item(DataGrid1.CurrentRowIndex, 1).ToString()

For each click the above event is fired and add to the label's text, but the
grid cell's value do not change, eventhough the checkbox visibly changes its
value. The true value is only displayed (in the label) on re-entering the
cell.

I need my code to run on the click event of the datagrid and the value of
the checkbox should determine what should happen.

How can I get the actual value (as displayed by the checkbox)?
 
E

Elton Wang

Following code shows how to get value from a checkbox:

Dim ck As CheckBox = CType(e.Item.FindControl("checkbox_ID"), CheckBox )
Dim ckValue = ck.Checked.ToString

HTH
 
P

PaulNaude

Thanks but I am not sure how to reference any particular records' checkbox in
my datagrid, other than by specifying the cell.

I tried : Dim ck As CheckBox =
CType(DataGrid1.Item(DataGrid1.CurrentRowIndex, 1), CheckBox) but obviously
is not right.

Where do you put your code? If I paste it into the datagrid click event ,
'item' is not a member of 'e'.

thanks
 
E

Elton Wang

Please show your html view code of datagrid.

BTW, where do you process checkbox, in datagrid_ItemCommand, or some other
event?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top