How to get value of checkbox from datagrid

  • Thread starter Thread starter JLuv
  • Start date Start date
J

JLuv

i've tried this method...

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

just to make sure that its reading the Checked bool correcty. but
Response.Write(i) always writes zero to the screen. i even went into
the debugger and it shows that no matter how many checkboxes i check,
the if statement always returns false.
any help?
 
Hello JLuv,

I think you've posted in the wrong newsgroup. Probably ASP.NET one is the
right one for you. But just to answer your question, I believe that you might
try to call .DataBind() every time. Try to add Page.IsPostBack check and
do DataBind only when the page is first retrieved i.e.


if (!Page.IsPostBack)
{
//do databind here..
}
 
Back
Top