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. Advertising

  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. Advertising

  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. 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. Stephan Bour
    Replies:
    1
    Views:
    502
    Hermit Dave
    Dec 12, 2003
  2. =?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:
    866
    David Wier
    Oct 6, 2006
  3. Joey Pang
    Replies:
    4
    Views:
    564
    Joey Pang
    Jun 13, 2005
  4. Imran Aziz

    checkbox value attribute in checkbox control ?

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

Share This Page