How to get checkbox value from datagrid...

Discussion in 'ASP .Net Datagrid Control' started by JLuv, Jun 27, 2006.

  1. JLuv

    JLuv Guest

    right now i'm trying the method...

    int i = 0;
    foreach (DataGridItem dgItem in pGrid.Items) //(int i = 0; i <
    pGrid.Items.Count; i++)
    {
    if (((CheckBox)dgItem.FindControl("check")).Checked)
    {
    i++;
    }
    }
    Response.Write(i);

    just to see if i'm getting the correct amount of checks. however, i've
    gone into the debugger and saw that it has each checkbox as false even
    when checked.
    now if i can get that part to work correctly, how would i get the data
    from the datagrid for each checked box?
    any help?
     
    JLuv, Jun 27, 2006
    #1
    1. Advertisements

  2. you can't do like that, as it sounds the correct way to do it...
    you ned to run all rows in the gridView instead itens...

    foreach (GridViewRow row in pGrid.Rows)
    {

    cb = ((CheckBox)row.FindControl("check")).Checked;

    }

    --

    Bruno Alexandre
    (a Portuguese in Københanv, Danmark)


    "JLuv" <> escreveu na mensagem
    news:...
    > right now i'm trying the method...
    >
    > int i = 0;
    > foreach (DataGridItem dgItem in pGrid.Items) //(int i = 0; i <
    > pGrid.Items.Count; i++)
    > {
    > if (((CheckBox)dgItem.FindControl("check")).Checked)
    > {
    > i++;
    > }
    > }
    > Response.Write(i);
    >
    > just to see if i'm getting the correct amount of checks. however, i've
    > gone into the debugger and saw that it has each checkbox as false even
    > when checked.
    > now if i can get that part to work correctly, how would i get the data
    > from the datagrid for each checked box?
    > any help?
    >
     
    Bruno Alexandre, Jun 30, 2006
    #2
    1. Advertisements

  3. JLuv

    MJ Guest

    Hi
    you try this.
    with one Template column,
    code
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:CheckBox --> Cheched ='<%# DataBinder.Eval(container,
    "dataitem.indicador")%>'
    -----------
    This field of database must is type Bit, with this best control when
    extract record since database

    Chress


    "Bruno Alexandre" escribió:

    > you can't do like that, as it sounds the correct way to do it...
    > you ned to run all rows in the gridView instead itens...
    >
    > foreach (GridViewRow row in pGrid.Rows)
    > {
    >
    > cb = ((CheckBox)row.FindControl("check")).Checked;
    >
    > }
    >
    > --
    >
    > Bruno Alexandre
    > (a Portuguese in Københanv, Danmark)
    >
    >
    > "JLuv" <> escreveu na mensagem
    > news:...
    > > right now i'm trying the method...
    > >
    > > int i = 0;
    > > foreach (DataGridItem dgItem in pGrid.Items) //(int i = 0; i <
    > > pGrid.Items.Count; i++)
    > > {
    > > if (((CheckBox)dgItem.FindControl("check")).Checked)
    > > {
    > > i++;
    > > }
    > > }
    > > Response.Write(i);
    > >
    > > just to see if i'm getting the correct amount of checks. however, i've
    > > gone into the debugger and saw that it has each checkbox as false even
    > > when checked.
    > > now if i can get that part to work correctly, how would i get the data
    > > from the datagrid for each checked box?
    > > any help?
    > >

    >
    >
    >
     
    MJ, Jun 30, 2006
    #3
  4. JLuv

    JLuv Guest

    i found my answer. i ended up doing a foreach loop like this...

    foreach (DataGridItem dgItem in theGrid.Items)
    {
    if (((CheckBox)dgItem.FindControl("select")).Checked)
    {
    myString = this.theGrid.Items.Cells[3].Text;
    //do other stuff
    }
    i++;
    }
     
    JLuv, Jun 30, 2006
    #4
    1. Advertisements

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. Stephan Bour
    Replies:
    1
    Views:
    558
    Hermit Dave
    Dec 12, 2003
  2. irene
    Replies:
    1
    Views:
    593
    Scott M.
    Oct 13, 2004
  3. John Dalberg
    Replies:
    0
    Views:
    460
    John Dalberg
    Dec 20, 2005
  4. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,023
    David Wier
    Oct 6, 2006
  5. Joey Pang
    Replies:
    4
    Views:
    844
    Joey Pang
    Jun 13, 2005
  6. John Dalberg

    How to get key value in a master datagrid from a detail datagrid?

    John Dalberg, Dec 20, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    224
    John Dalberg
    Dec 20, 2005
  7. Imran Aziz

    checkbox value attribute in checkbox control ?

    Imran Aziz, Aug 6, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    354
    Imran Aziz
    Aug 8, 2005
  8. randy
    Replies:
    13
    Views:
    770
    Tad McClellan
    Nov 1, 2003
Loading...