473,624 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 OnCheckedChange d event to the checkbox and implemented
the method with the following code:

for (int i = 0; i<this.DataGrid 1.Items.Count; i++)
{
CheckBox cb=
(CheckBox)DataG rid1.Items[i].FindControl("c hkContribute");
if (cb.Checked)
{
((CheckBox)Data Grid1.Items[i].FindControl("c hkPrice")).Chec ked =
true;
}
}
Session["CachedSour ce"] = 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 1325
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*********@gm ail.comwrote in message
news:11******** **************@ 75g2000cwc.goog legroups.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 OnCheckedChange d event to the checkbox and implemented
the method with the following code:

for (int i = 0; i<this.DataGrid 1.Items.Count; i++)
{
CheckBox cb=
(CheckBox)DataG rid1.Items[i].FindControl("c hkContribute");
if (cb.Checked)
{
((CheckBox)Data Grid1.Items[i].FindControl("c hkPrice")).Chec ked =
true;
}
}
Session["CachedSour ce"] = 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
1564
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. Users have to press a checkbox to specify whether they want to use DataGrid to provide break-up or provide total value in textbox. Now when checkbox is unchecked I am setting the Enabled property of DataGrid to False and vice versa. The problem is...
0
2152
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 these selected fields and allow user to click one or more CheckBox controls to activate this bit on the database table for a required ID. I have already added a template column to the DataGrid and I can get the
4
1513
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 HeaderText="Check In"> <ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle> <ItemTemplate> <asp:CheckBox id="chkReturn" runat="server" OnCheckedChanged="CheckItIn"></asp:CheckBox>
2
2027
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 Page for a control. You have two columns -- the first column is a simple caption, and the second column can be one of a number of controls (textbox, checkbox, dropdownlist, etc) for each row. So row #1 might have a textbox in the second column,...
9
1263
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 it you will see the complete news message. When you see the complete news message you don't see the datagrid anymore. In the news message you can click on a link with a text "back"... once you
4
1843
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
1965
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 records from a stored procedure. Be selecting multiple datarows using a checkbox. All i want to do is update a field called 'Active' datatype bit from 0 to 1
1
4227
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 the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn Class:-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-**-*-*-*
5
2893
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, I am appending all the directories with 0 & all the files with 1. Moreover, each directory & file listed in the DataGrid will have a corresponding CheckBox. To differentiate between directories & files, I am adding the string "*D" (without the...
0
8238
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8174
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8624
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1786
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.