How to get checkbox value from datagrid...

J

JLuv

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?
 
B

Bruno Alexandre

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;

}
 
M

MJ

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ó:
 
J

JLuv

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++;
}
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top