473,701 Members | 2,918 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CheckBox unchecked status detection in DataGrid Template Column

Hi Everyone,

I have a dynamic checkbox in a datagrid that uses the ITemplate interface
and has the checkchanged event wired up. When the checkbox is checked, the
event
event handler that handles the event gets called, however when it is
unchecked, it does not fire. Is this by design, or is something else that
is going on? Thanks!!.

This message was originally posted by ma****@discussi ons.microsoft.c om, but
since she hasn't get any response and I'm experiencing the same issue, I'm
posting it here.

Regards,
Javier.
Dec 12 '05 #1
2 2705
Post some snippet code and it would be easier to see what you are trying to
do
Patrick

"Javier" <jt*******@htp. bcit.ca> wrote in message
news:uw******** ******@TK2MSFTN GP12.phx.gbl...
Hi Everyone,

I have a dynamic checkbox in a datagrid that uses the ITemplate interface
and has the checkchanged event wired up. When the checkbox is checked, the event
event handler that handles the event gets called, however when it is
unchecked, it does not fire. Is this by design, or is something else that
is going on? Thanks!!.

This message was originally posted by ma****@discussi ons.microsoft.c om, but since she hasn't get any response and I'm experiencing the same issue, I'm
posting it here.

Regards,
Javier.

Dec 12 '05 #2
Hi Patrick,
Ok, here's the code.

This is the template column that hosts the header and items checkboxes
:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
using System.Collecti ons;
using System.Collecti ons.Specialized ;
namespace ASPnetControls. WebControls
{
public class CheckBoxTemplat eColumn : TemplateColumn
{
private string headerCheckBoxT ooltip;
private CustomCheckBoxH eader headerCheckBox;
private CustomCheckBoxI tem itemCheckBox;

public string CheckBoxHeaderT ooltip
{
set{this.header CheckBoxTooltip = value;}
}

public override void Initialize()
{
headerCheckBox = (headerCheckBox Tooltip != null)? new
CustomCheckBoxH eader(headerChe ckBoxTooltip) : new CustomCheckBoxH eader();
base.HeaderTemp late = headerCheckBox;
itemCheckBox = new CustomCheckBoxI tem();
base.ItemTempla te = itemCheckBox;
itemCheckBox.Pr eRender = new EventHandler(it emCheckBox_PreR ender);
base.Initialize ();
}

private void itemCheckBox_Pr eRender(object sender, EventArgs e)
{
CustomCheckBoxI tem itemCheckBox = (CustomCheckBox Item)sender;
itemCheckBox.Js HeaderArray = headerCheckBox. JsHeaderArray;
itemCheckBox.Js ItemsArray = headerCheckBox. JsItemsArray;
}

// internal member
private abstract class CustomCheckBox : CheckBox, ITemplate
{
protected const string JavaScriptBlock Formatter = "<script
language=\"java script\">{0}</script>";
protected string jsHeaderArray, jsItemsArray;

#region ITemplate Members
public virtual void InstantiateIn(C ontrol container)
{
container.Contr ols.Add(this);
}
#endregion
}

// internal member
private class CustomCheckBoxH eader : CustomCheckBox
{
public CustomCheckBoxH eader(string tooltip)
{
this.Attributes .Add("title", tooltip);
}

public CustomCheckBoxH eader(){}

public string JsHeaderArray
{
get{return base.jsHeaderAr ray;}
}

public string JsItemsArray
{
get{return base.jsItemsArr ay;}
}

protected override void OnPreRender(Eve ntArgs e)
{
base.jsHeaderAr ray = this.ClientID;
base.jsItemsArr ay = base.jsHeaderAr ray + "_";
this.Page.Regis terArrayDeclara tion(base.jsHea derArray,
String.Format(" '{0}'", jsHeaderArray)) ;
this.Page.Regis terClientScript Block("Initiali zeHeaderCheckBo x",
String.Format(J avaScriptBlockF ormatter, @"function InitializeHeade rCheckBox
(itemsArray, headerArray)
{
controllerRef = document.getEle mentById(header Array[0]);
controllerRef.o nclick = function()
{
for(i=0; itemsArray.leng th > i; ++i)
{
controlleeRef = document.getEle mentById(itemsA rray[i]);
if(!controlleeR ef.disabled)
controlleeRef.c hecked = this.checked;
};
}
checkedCount = 0;
disabledCount = 0;
for(i=0; itemsArray.leng th > i; ++i)
{
controlleeRef = document.getEle mentById(itemsA rray[i]);
if(controlleeRe f.checked)
checkedCount++;
if(controlleeRe f.disabled)
disabledCount++ ;
}
controllerRef.d isabled = disabledCount == itemsArray.leng th;
controllerRef.c hecked = checkedCount == itemsArray.leng th;
}"));
this.Page.Regis terStartupScrip t(base.jsHeader Array,
String.Format(J avaScriptBlockF ormatter,
String.Format(" InitializeHeade rCheckBox({0},{ 1});",
base.jsItemsArr ay, base.jsHeaderAr ray)));
}
}

// internal member
private class CustomCheckBoxI tem : CustomCheckBox
{
public new EventHandler PreRender;
public string JsHeaderArray
{
set{base.jsHead erArray = value;}
}

public string JsItemsArray
{
set{base.jsItem sArray = value;}
}

public override void InstantiateIn(C ontrol container)
{
CustomCheckBoxI tem cb = new CustomCheckBoxI tem();
cb.PreRender = this.PreRender;
container.Contr ols.Add(cb);
}

protected override void OnPreRender(Eve ntArgs e)
{
PreRender(this, e);
this.Page.Regis terArrayDeclara tion(base.jsIte msArray,
String.Format(" '{0}'", this.ClientID)) ;
this.Page.Regis terClientScript Block("Initiali zeItemsCheckBox es",
String.Format(J avaScriptBlockF ormatter, @"function InitializeItems CheckBoxes
(itemsArray, headerArray)
{
var CheckBoxArrayTe ster = function(s)
{
for(i=0; s.length > i; ++i)
{
controlleeRef = document.getEle mentById(s[i]);
if (controlleeRef. checked)
continue;
else
return true;
}
}
for(i=0; itemsArray.leng th > i; ++i)
{
document.getEle mentById(itemsA rray[i]).onclick = function()
{
controllerRef = document.getEle mentById(header Array[0]);
if (this.checked && CheckBoxArrayTe ster(itemsArray ) != true)
controllerRef.c hecked = true;
else if (!this.checked && CheckBoxArrayTe ster(itemsArray ))
controllerRef.c hecked = false;
}
}
}"));
this.Page.Regis terStartupScrip t(base.jsItemsA rray,
String.Format(J avaScriptBlockF ormatter,
String.Format(" InitializeItems CheckBoxes({0}, {1});",
base.jsItemsArr ay, base.jsHeaderAr ray)));
}
}
}
}

-------------------------- Page class that hosts the datagrid with the
template
column ------------------------------------------------------------------------------
aspx file ->

<%@ Page language="c#" Codebehind="Web Form2.aspx.cs" AutoEventWireup ="false"
Inherits="Conte ntManager.WebFo rm2" %>
<%@ Register TagPrefix="aspn etw" Namespace="ASPn etControls.WebC ontrols"
Assembly="ASPne tControls"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2 </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server" DataSource='<%# new
string[]{"a","b","c","d ","e","f","g"," h","i"} %>'
AutoGenerateCol umns="True">
<Columns>
<aspnetw:CheckB oxTemplateColum n/>
</Columns>
</asp:DataGrid>
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 648px; POSITION:
absolute; TOP: 24px" runat="server"
Text="Button"></asp:Button>
</form>
</body>
</HTML>

cs file ->

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace ContentManager
{
/// <summary>
/// Summary description for WebForm2.
/// </summary>
public class WebForm2 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Butt on Button1;
protected System.Web.UI.W ebControls.Data Grid DataGrid1;

private void Page_Load(objec t sender, System.EventArg s e)
{
if(!this.IsPost Back)
DataGrid1.DataB ind();
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{

this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
}
}

------------------------------------------------------------------------------------------------------------------------------------------------------------
Everything works fine, except for keeping the state and getting called the
event handler only when a checkbox is set to unchecked after having been
checked.

Thanks in advance,
Javier.


"Patrick.O. Ige" <na********@tou ghguy.net> wrote in message
news:eN******** *****@tk2msftng p13.phx.gbl...
Post some snippet code and it would be easier to see what you are trying
to
do
Patrick

"Javier" <jt*******@htp. bcit.ca> wrote in message
news:uw******** ******@TK2MSFTN GP12.phx.gbl...
Hi Everyone,

I have a dynamic checkbox in a datagrid that uses the ITemplate interface
and has the checkchanged event wired up. When the checkbox is checked,

the
event
event handler that handles the event gets called, however when it is
unchecked, it does not fire. Is this by design, or is something else
that
is going on? Thanks!!.

This message was originally posted by ma****@discussi ons.microsoft.c om,

but
since she hasn't get any response and I'm experiencing the same issue,
I'm
posting it here.

Regards,
Javier.


Dec 12 '05 #3

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

Similar topics

3
4854
by: Randy | last post by:
Hello, I'm creating a table on the fly that is used by a datagrid. I'm also creating a tableStyle that is used for the datagrid to make it look like I want. I'm using the DataGridBoolColumn to make one column a CheckBox field. It shows up fine...as a CheckBox. I looped through the table and stored a true or false in the checkbox column but it appears to have no effect on the checkbox column. No matter what I store there (true/false), when...
2
7542
by: michael walser | last post by:
display checkbox in datagrid. I find that there are 3 status: checked - check box with click icon unchecked - blank in check box unknown - click icon but color in gray..... How can I set the check box only 2 status, checked and unchecked?
0
2156
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
0
2401
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a CheckBox Programmatically" in my code. I have changed it to use a OLDDB.DBReader to populate the datagrid and for the databinding. It works perfectly - also when using the edit-mode in the datagrid.
1
4158
by: iforsyth | last post by:
Have a paging datagrid with a checkbox control in column(0). ViewState is enabled. I check the checkbox in first row of the grid on a page and then the program hits this event: Private Sub dgRegGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgRegGrid.PageIndexChanged I then do a loop to check the checkbox state.
1
663
by: Machi | last post by:
Let say i select rows of records with 4 columns from Database and want to display the data in DataGrid (ASP.NEt Server Control) with one column which must be displayed in CheckBox layout. For the column (which contains checkbox), when i click the CheckBox in the Header of DataGrid, all the rows (for column which contains Checkboxes) must be checked. When i uncheck the checkbox in Header of DataGrid, all the rows of that column must be unchecked,...
1
1319
by: Chen Sun via .NET 247 | last post by:
I have a datagrid with a checkbox column, if i check onecheckbox, and then change to another page, when i go back to theprevious page, the checkbox that i have marked is uncheckedagain, is there anyway to make the checkbox still checked when ireturn to the original page ? ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>MxzCEhq3gUKJ/BvK7JcXdw==</Id>
10
2437
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox control in a datagrid? Now I have a Select column but the problem is that the user needs to select more than one record and send them all to print, instead of being one by one like is now with the Select column. Another question, is it possible to...
6
1714
by: Bill Nguyen | last post by:
I need to add a checkbox in front of all the rows in a datagrid so that users can select/unselect them. Any help is greatly appreciated! Bill
0
8649
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
9232
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
9084
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...
0
8936
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
7827
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5905
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4665
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.