473,327 Members | 2,090 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,327 software developers and data experts.

checkboxes dynamically

I create 2 groupes of checkboxes dynamically (I don't use checkboxlist) for 2
differnet zones in my aspx web page and I assign a "onClick" javascript
handler by group., lets say the first 4 chboxes have evHandler1 and the other
4 chboxes have evHandler2
Of course each checkbox has an id and name which comes from DB lookup tables.
At the top of each group, there is a special checkbox, if checked by the
user, I need to write a javascript that loop through checkboxes in the group
and uncheck any
of the checked checkboxes in that group.
I can do it easily for radio buttions because they have the groupname
property, checkboxes don't have this property.
I amnot expert in javascript so I would appreciate any idea or tip to
achieve this

Thanks in advance
Oct 26 '06 #1
8 1619
Hi,

Based on my understanding, your question is how to treat several checkbox
as a group in javascript/dhtml. Please correct me if I've misunderstood
anything.

I think you can use following javascript:

#JavaScript Toolbox - CheckBox / Check Box Group
http://www.mattkruse.com/javascript/checkboxgroup/

Let me know if you need further information on how to achieve your specific
objective. Thanks.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 26 '06 #2
Exactly, example 2 is what I need to do. However, as I said in a second post
, in the code behind, I can not assign the value "name" to the control. I can
do it for the id, when browsing, aparently .net assigns trhe ID value as the
name value for the control.
So according to the link you provided, I need to dosomething like this
id="1" name = "checkbox1"
id="2" name = "checkbox2"
...
....
so how this can be achieved in the code behind. last question, what is the
best way to use this library? should I write it as a big string in the code
behind or write it in a separate js file? can please give me some hints.
So many thanks

"Walter Wang [MSFT]" wrote:
Hi,

Based on my understanding, your question is how to treat several checkbox
as a group in javascript/dhtml. Please correct me if I've misunderstood
anything.

I think you can use following javascript:

#JavaScript Toolbox - CheckBox / Check Box Group
http://www.mattkruse.com/javascript/checkboxgroup/

Let me know if you need further information on how to achieve your specific
objective. Thanks.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 26 '06 #3
I forgot to say that I didn'tfind how to set the attribute "Value" for the
checkbox in the code behind as well as the "name" attribute

Thanks

"Walter Wang [MSFT]" wrote:
Hi,

Based on my understanding, your question is how to treat several checkbox
as a group in javascript/dhtml. Please correct me if I've misunderstood
anything.

I think you can use following javascript:

#JavaScript Toolbox - CheckBox / Check Box Group
http://www.mattkruse.com/javascript/checkboxgroup/

Let me know if you need further information on how to achieve your specific
objective. Thanks.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 26 '06 #4
Again so many thanks. I switched to to outloook express, downloaded the zip
file, I can extract all files except the javascript one. windows doesn't
allow. I have Windows firewall off.

One thing to mention, and sorry for that , In fact my needs is when first
item is checked, I need to uncheck all other check boxes in the group and not
check the boxes. So I think the code should do the the inverse, where should
I do that in your JS file of the C sharpe.

One last thing, how did you test your control? what I mean is I haev already
an aspx page which I said create dynamically the checkboxes and they are
bound to different code. So, correct me If i AM MISTAKEN, inyour Csharpe
code, I dont see how to add the check boxes
Is it possible to send me the js file and a test file on my email directly
"Walter Wang [MSFT]" wrote:
Hi,

I've created a customized CheckBoxList control for you which has the
behavior: the first item will be the control item, when it's checked, all
other items are checked; when it's unchecked, all other items are unchecked.

using System;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

[assembly: WebResource("CheckBoxListExLib.CheckBoxGroup.js",
"text/javascript")]

namespace CheckBoxListExLib
{
public class CheckBoxListEx : CheckBoxList
{
protected override void OnPreRender(EventArgs e)
{
Type type = typeof(CheckBoxListEx);
string url = Page.ClientScript.GetWebResourceUrl(type,
"CheckBoxListExLib.CheckBoxGroup.js");
if (!Page.ClientScript.IsClientScriptIncludeRegistere d(type,
type.FullName))
Page.ClientScript.RegisterClientScriptInclude(type ,
type.FullName, url);

if (!Page.ClientScript.IsClientScriptBlockRegistered( GetType(),
ClientID))
{
StringBuilder sb = new StringBuilder();
sb.Append(string.Format("var {0} = new CheckBoxGroup();",
GroupID));

for (int i = 0; i < Items.Count; i++)
{
string id = ClientID + "$" + i.ToString();
sb.Append(string.Format("{0}.addToGroup('{1}');",
GroupID, id));
if (i == 0)
{

sb.Append(string.Format("{0}.setControlBox('{1}'); ", GroupID, id));

sb.Append(string.Format("{0}.setMasterBehavior('al l');", GroupID));
}
}

Page.ClientScript.RegisterClientScriptBlock(GetTyp e(),
ClientID, sb.ToString(), true);
}

base.OnPreRender(e);
}

protected virtual string GroupID
{
get { return ClientID + "_CG"; }
}

protected override void RenderItem(ListItemType itemType, int
repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
Items[repeatIndex].Attributes.Add("onclick",
string.Format("{0}.check(this)", GroupID));
base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
}
}
}
I've attached a complete class library project for your reference. The
javascript will be embedded in the assembly. You can use this control as
where you need to use CheckBoxList. (You may have to use Outlook Express to
download the attachment)
Oct 26 '06 #5
One thing to mention, I work in VS 2003 and not 2005

"Walter Wang [MSFT]" wrote:
Hi,

I've created a customized CheckBoxList control for you which has the
behavior: the first item will be the control item, when it's checked, all
other items are checked; when it's unchecked, all other items are unchecked.

using System;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

[assembly: WebResource("CheckBoxListExLib.CheckBoxGroup.js",
"text/javascript")]

namespace CheckBoxListExLib
{
public class CheckBoxListEx : CheckBoxList
{
protected override void OnPreRender(EventArgs e)
{
Type type = typeof(CheckBoxListEx);
string url = Page.ClientScript.GetWebResourceUrl(type,
"CheckBoxListExLib.CheckBoxGroup.js");
if (!Page.ClientScript.IsClientScriptIncludeRegistere d(type,
type.FullName))
Page.ClientScript.RegisterClientScriptInclude(type ,
type.FullName, url);

if (!Page.ClientScript.IsClientScriptBlockRegistered( GetType(),
ClientID))
{
StringBuilder sb = new StringBuilder();
sb.Append(string.Format("var {0} = new CheckBoxGroup();",
GroupID));

for (int i = 0; i < Items.Count; i++)
{
string id = ClientID + "$" + i.ToString();
sb.Append(string.Format("{0}.addToGroup('{1}');",
GroupID, id));
if (i == 0)
{

sb.Append(string.Format("{0}.setControlBox('{1}'); ", GroupID, id));

sb.Append(string.Format("{0}.setMasterBehavior('al l');", GroupID));
}
}

Page.ClientScript.RegisterClientScriptBlock(GetTyp e(),
ClientID, sb.ToString(), true);
}

base.OnPreRender(e);
}

protected virtual string GroupID
{
get { return ClientID + "_CG"; }
}

protected override void RenderItem(ListItemType itemType, int
repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
Items[repeatIndex].Attributes.Add("onclick",
string.Format("{0}.check(this)", GroupID));
base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
}
}
}
I've attached a complete class library project for your reference. The
javascript will be embedded in the assembly. You can use this control as
where you need to use CheckBoxList. (You may have to use Outlook Express to
download the attachment)
Oct 26 '06 #6
Also, maybe I was not very clear about the fact that as I said I have 2
different groups and when the master control in checked, there is a
javascript that would execute that update some different stuff in an xml
database. If I follow your logic, I should create 2 controls with each one
has its check method unchecks the other checboxes and execute the custom code
regarding updating the database., NON?

"Walter Wang [MSFT]" wrote:
Hi,

I've created a customized CheckBoxList control for you which has the
behavior: the first item will be the control item, when it's checked, all
other items are checked; when it's unchecked, all other items are unchecked.

using System;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

[assembly: WebResource("CheckBoxListExLib.CheckBoxGroup.js",
"text/javascript")]

namespace CheckBoxListExLib
{
public class CheckBoxListEx : CheckBoxList
{
protected override void OnPreRender(EventArgs e)
{
Type type = typeof(CheckBoxListEx);
string url = Page.ClientScript.GetWebResourceUrl(type,
"CheckBoxListExLib.CheckBoxGroup.js");
if (!Page.ClientScript.IsClientScriptIncludeRegistere d(type,
type.FullName))
Page.ClientScript.RegisterClientScriptInclude(type ,
type.FullName, url);

if (!Page.ClientScript.IsClientScriptBlockRegistered( GetType(),
ClientID))
{
StringBuilder sb = new StringBuilder();
sb.Append(string.Format("var {0} = new CheckBoxGroup();",
GroupID));

for (int i = 0; i < Items.Count; i++)
{
string id = ClientID + "$" + i.ToString();
sb.Append(string.Format("{0}.addToGroup('{1}');",
GroupID, id));
if (i == 0)
{

sb.Append(string.Format("{0}.setControlBox('{1}'); ", GroupID, id));

sb.Append(string.Format("{0}.setMasterBehavior('al l');", GroupID));
}
}

Page.ClientScript.RegisterClientScriptBlock(GetTyp e(),
ClientID, sb.ToString(), true);
}

base.OnPreRender(e);
}

protected virtual string GroupID
{
get { return ClientID + "_CG"; }
}

protected override void RenderItem(ListItemType itemType, int
repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
{
Items[repeatIndex].Attributes.Add("onclick",
string.Format("{0}.check(this)", GroupID));
base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
}
}
}
I've attached a complete class library project for your reference. The
javascript will be embedded in the assembly. You can use this control as
where you need to use CheckBoxList. (You may have to use Outlook Express to
download the attachment)
Oct 26 '06 #7
Hi,

Sorry for my misunderstanding that you're using .NET 2.0.

I understand that you've already have code that dynamically creates the
checkboxes, so I think we will continue the work from your existing code.

I think you need to do following changes:
1) Get the javascript from the website I mentioned at my first reply and
save it as a .js file and add it to your web app
2) In your web form, include the javascript
3) Since your desired behavior is to clear other checkboxes when the
controlling checkbox is checked, you need to change following javascript
code:

function CBG_check(obj) {
....

if (this.masterBehavior=="all") {
for (i=0;i<this.checkboxNames.length;i++) {
this.checkboxNames[i].checked=checked; }
just change to "...[i].checked=!checked"

4) Construct a javascript code block dynamically in your code-behind to use
the javascript library. Just remember that the client-side name attribute
is from server-side UniqueID property. Then register this javascript code
block to your Page class.

Please let me know if you need further information. If you need complete
code example, please send me your webform first so that I can directly make
the modifications based on your code, that will make more sense. Thanks.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 27 '06 #8
HI, I have sent you a mail with a zip file. Please confirm
Thanks

"Walter Wang [MSFT]" wrote:
Hi,

Sorry for my misunderstanding that you're using .NET 2.0.

I understand that you've already have code that dynamically creates the
checkboxes, so I think we will continue the work from your existing code.

I think you need to do following changes:
1) Get the javascript from the website I mentioned at my first reply and
save it as a .js file and add it to your web app
2) In your web form, include the javascript
3) Since your desired behavior is to clear other checkboxes when the
controlling checkbox is checked, you need to change following javascript
code:

function CBG_check(obj) {
....

if (this.masterBehavior=="all") {
for (i=0;i<this.checkboxNames.length;i++) {
this.checkboxNames[i].checked=checked; }
just change to "...[i].checked=!checked"

4) Construct a javascript code block dynamically in your code-behind to use
the javascript library. Just remember that the client-side name attribute
is from server-side UniqueID property. Then register this javascript code
block to your Page class.

Please let me know if you need further information. If you need complete
code example, please send me your webform first so that I can directly make
the modifications based on your code, that will make more sense. Thanks.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 28 '06 #9

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

Similar topics

0
by: Frank Collins | last post by:
Can anyone point me to some good examples on the web of using values from dynamically created checkboxes on forms in ASP, particularly relating to INSERTING those values into a SQL or Access...
3
by: Ondernemer | last post by:
Hi guys, On my page I dynamically create different checkboxes. <input type="checkbox" name="ch1" value="some value"> option 1 <input type="checkbox" name="ch2" value="some value"> option 2...
2
by: Mortar | last post by:
i have a datagrid with a column of html checkboxes which are created dynamically. The id/name of the checkboxes comes from a value in the database. on a postback, i would like to get all the...
7
by: DJ Dev | last post by:
Hi All, I have a complex problem. I have dropdownlists (usually 3-5) and the user selects some value from these and for each value selected, datagrids are shown to the user. I am creating the...
1
by: zoneal | last post by:
Hello there, Currently I am working with the project which needs dynamically generated checkboxes and i have generated dynamic checkboxes but i am facing problem with getting the value of...
1
by: SalamElias | last post by:
When I add checkboxes dynamically, I can set several attributes(id, eventhandlers specific to checkboxes....) in code. I decided to use the checkboxlist to generate several checkboxes dynamically...
3
by: somaskarthic | last post by:
Hi How to get the values of dynamically created checkboxes which are checked and unchecked (for both the conditions). Only the selected checkbox values are posted as 'On' . How can i get the value...
7
by: Srikanth Ram | last post by:
Hi, I'm creating a PHP application. In this a dynamic table with the fields in the database is generated in a page. I have placed a checkbox in each row of the table to approve/disapprove...
16
by: sarega | last post by:
Hi, There is an array whose length varies dynamically on the users input, I have to provide checkboxes for this array along with the value of the array and based on the checkboxes selected by the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.