Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataGrid - Checking one checkbox when the other is clicked

Reply
Thread Tools

DataGrid - Checking one checkbox when the other is clicked

 
 
arun.hallan@gmail.com
Guest
Posts: n/a
 
      08-16-2006
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[i].FindControl("chkContribute");
if (cb.Checked)
{
((CheckBox)DataGrid1.Items[i].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?

 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      08-16-2006
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!
*************************************************
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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[i].FindControl("chkContribute");
> if (cb.Checked)
> {
> ((CheckBox)DataGrid1.Items[i].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?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid and embeded Checkbox..How to find if checkbox clicked =?Utf-8?B?RG90TmV0RGV2?= ASP .Net 1 10-06-2006 04:11 PM
Howto bind CheckBox to the datagrid/ Then update the database field when the checkbox is clicked. Joey Pang ASP .Net Datagrid Control 4 06-13-2005 02:29 AM
CheckBox loses state with when HyperLink clicked mschoup@excite.com ASP .Net 1 03-15-2005 03:18 PM
Checking One Box when I check a second checkbox Rich Javascript 2 05-18-2004 06:12 PM
HELP - select all checkbox javascript works fine.. unless there is only one checkbox. Michael Champagne Javascript 4 04-20-2004 01:40 AM



Advertisments