check box in datagrid
-
Hi all, I have checkboxes in datagrid to select and a delete button outside the datagrid to delete the checked row in datagrid. After checking the check box and clicking the delete button, in the btndelete_Click im finding the check box in the datagrid and deleting the particular record, but im getting the checked false in the btndelete_Click of the datagrid checkbox which is checked. Please tell me why it is so and how can i find the checkbox of datagrid is checked or not in button click. The code is below:
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (DataGridItem DemoGridItem in grid.Items)
{
CheckBox oCheckbox = (CheckBox)DemoGridItem.Cells[1].FindControl("chkDelete");
HiddenField hidImageName = (HiddenField)DemoGridItem.Cells[1].FindControl("hdnItem");
if (oCheckbox.Checked == true)
{try { Delete code; } catch( Exception e) { } } }
}
Thanks in advance for ur help.
-
Hi all, I have checkboxes in datagrid to select and a delete button outside the datagrid to delete the checked row in datagrid. After checking the check box and clicking the delete button, in the btndelete_Click im finding the check box in the datagrid and deleting the particular record, but im getting the checked false in the btndelete_Click of the datagrid checkbox which is checked. Please tell me why it is so and how can i find the checkbox of datagrid is checked or not in button click. The code is below:
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (DataGridItem DemoGridItem in grid.Items)
{
CheckBox oCheckbox = (CheckBox)DemoGridItem.Cells[1].FindControl("chkDelete");
HiddenField hidImageName = (HiddenField)DemoGridItem.Cells[1].FindControl("hdnItem");
if (oCheckbox.Checked == true)
{try { Delete code; } catch( Exception e) { } } }
}
Thanks in advance for ur help.
The real question is, where do the checkboxes come from ? Best guess, your page load is binding to the datasource and erasing any selected items.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.