Checkbox value in datagrid does not reflect appearance

Discussion in 'ASP .Net Datagrid Control' started by PaulNaude, Nov 3, 2005.

  1. PaulNaude

    PaulNaude Guest

    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)?
     
    PaulNaude, Nov 3, 2005
    #1
    1. Advertising

  2. PaulNaude

    Elton Wang Guest

    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

    "PaulNaude" <> wrote in message
    news:...
    >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)?
     
    Elton Wang, Nov 3, 2005
    #2
    1. Advertising

  3. PaulNaude

    PaulNaude Guest

    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

    "Elton Wang" wrote:

    > 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
    >
    > "PaulNaude" <> wrote in message
    > news:...
    > >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)?

    >
    >
    >
     
    PaulNaude, Nov 4, 2005
    #3
  4. PaulNaude

    Elton Wang Guest

    Please show your html view code of datagrid.

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


    "PaulNaude" <> wrote in message
    news:...
    > 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
    >
    > "Elton Wang" wrote:
    >
    >> 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
    >>
    >> "PaulNaude" <> wrote in message
    >> news:...
    >> >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)?

    >>
    >>
    >>
     
    Elton Wang, Nov 4, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sunil Thomas
    Replies:
    0
    Views:
    530
    Sunil Thomas
    Sep 29, 2003
  2. =?Utf-8?B?SlQ=?=
    Replies:
    1
    Views:
    3,683
    Hansen
    Jun 29, 2011
  3. Brandon
    Replies:
    1
    Views:
    229
    Anthony Jones
    Jun 6, 2007
  4. McKirahan
    Replies:
    8
    Views:
    184
    McKirahan
    Oct 12, 2005
  5. Replies:
    12
    Views:
    240
    Thomas 'PointedEars' Lahn
    Dec 6, 2005
Loading...

Share This Page