DataGrid - Checking one checkbox when the other is clicked

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

Cowboy \(Gregory A. Beamer\)

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!
*************************************************
 

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,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top