473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DataGrid - Checking one checkbox when the other is clicked

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?

Aug 16 '06 #1
1 1312
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!
*************************************************
<ar*********@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro 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?

Aug 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Job Lot | last post by:
I have an Expense Data Entry form which contains a DataGrid showing various expense categories. There are three columns Description, Cash Exp, Credit Exp, where Description column is readonly. ...
0
by: Just D | last post by:
Hi All, Does anybody know how to write the following code? I have a database table with a few columns including: ID , "Task" , ForceRun . I need to show the DataGrid on the ASPX page with...
4
by: Jim Heavey | last post by:
Hello, I am starting to learn how to use the Datagrid and I have a couple of questions. My datagrid as a checkbox in it. It looks like the following in the datagrid... <asp:TemplateColumn...
2
by: Colin McGuigan | last post by:
This is a translation of an ASP page to ASP.Net. First, the background: The goal is to have a grid of different settings for the application -- think something along the lines of the Property...
9
by: Arjen | last post by:
Hello, I'm using a datagrid for a news module. The datagrid only displays the news title, date and header. (this is allready working) Now I want to make the title clickable... if you click on...
4
by: Mike | last post by:
Hi, Is there a possibility to have one of the Web Control Datagrid's column as a Calendar when editing data? Any resources on this subject? Thanks Mike
1
by: Wolffang | last post by:
From: "Wolffang" <javid@techlite.co.uk> Subject: How to do a multiple select and update in a datagrid Date: 23 October 2004 21:28 Using Visual studio.net VB I have a datagrid that brings...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
5
by: rn5a | last post by:
In my application, I want to populate all the directories & files existing in a directory on the server in a DataGrid. To ensure that all the directories get listed first followed by all the files,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.