DataGrid - Checking one checkbox when the other is clicked

  • Thread starter Thread starter arun.hallan
  • Start date Start date
A

arun.hallan

Hi,

I have two columns in a datagrid that are filled with checkboxes.

I want one checkbox in a row to be checked when the corresponding
checkbox is checked.

I've added an OnCheckedChanged event to the checkbox and implemented
the method with the following code:

for (int i = 0; i<this.DataGrid1.Items.Count; i++)
{
CheckBox cb=
(CheckBox)DataGrid1.Items.FindControl("chkContribute");
if (cb.Checked)
{
((CheckBox)DataGrid1.Items.FindControl("chkPrice")).Checked =
true;
}
}


Session["CachedSource"] = this.DataGrid;

But the postback doesnt save the datagrid selections.

Am i doing this correct and if not is there an easier way?
 
You are probably rebinding the page with each hit, which overwrites the
click. Move all of your manipulation code into the control events and only
set the initial load in Page_Load. The viewstate bits happen between init
and Page_Load and the control events happen after. At that point, you should
be rebound from viewstate.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
 
Back
Top