473,387 Members | 1,583 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,387 software developers and data experts.

Mutually Exclusive CHeckboxes in a GridView

83
Hii experts,

I 've a gridview with one template coloumn with checkbox in that,which is used to to select the row..so once the user select one perticular checkbox..it has to clear the checkbox already in checked state ..i.e. at a time hes allowed to select only one checkbox.(checkboxes should be mutually exclusive)

Requesting you all kindly tell me how to implement this .

Thanks in advance..

Rgds,
BTR.
Jan 28 '09 #1
9 6585
Dormilich
8,658 Expert Mod 8TB
better use a radio button, there is only one allowed for selection (given they have the same name attribute)
Jan 28 '09 #2
btreddy
83
Hii Thanks for your reply....but i would like to provide an option like user should be able to deselect the selected check box thts the reason why i choose checkboxes.

Kincly provide me the solution.

Rgds,
BTR.
Jan 28 '09 #3
acoder
16,027 Expert Mod 8TB
How about a "None of the above" option?
Jan 28 '09 #4
btreddy
83
if the user wants to modify the details of any row in the gridview he will select the checkbox in the perticular row and cilck the "edit" button.

so i wanna to allow the user to select only one row for editing at a time .This is what my requirment is.
Jan 28 '09 #5
Dormilich
8,658 Expert Mod 8TB
like acoder said, if you want to deselect all radio buttons, make a click button that will do that (call it maybe "unselect all"), that's far easier that trying to force the checkbuttons.
Jan 28 '09 #6
acoder
16,027 Expert Mod 8TB
You could allow them to edit more than one row at any one time.

Anyway, to answer your question, one way is to set all their checked properties to false. Then set the clicked one to true. The alternative proposed by Dormi makes more sense though.
Jan 28 '09 #7
btreddy
83
Thank you very much for your replies.

I solved it by using javascript.

Expand|Select|Wrap|Line Numbers
  1. function uncheckOthers(id)
  2.     {        
  3.         var elm = document.getElementsByTagName('input');        
  4.         for(var i = 0; i < elm.length; i++)
  5.         {                            
  6.             if(elm.item(i).id.substring(id.id.lastIndexOf('_')) == id.id.substring(id.id.lastIndexOf('_')))
  7.             {
  8.                 if( elm.item(i).type == "checkbox" && elm.item(i)!=id)
  9.                     elm.item(i).checked = false;
  10.             }
  11.         }
  12.     } 
and in the codebehind
Expand|Select|Wrap|Line Numbers
  1. protected void GridViewParticipants_OnRowDataBound(object sender, GridViewRowEventArgs e)
  2. {
  3. if (e.Row.RowType == DataControlRowType.DataRow)
  4.  {
  5.             string strScript = "uncheckOthers(" + ((CheckBox)e.Row.Cells[0].FindControl("chkselect")).ClientID + ");";
  6.             ((CheckBox)e.Row.Cells[0].FindControl("chkselect")).Attributes.Add("onclick", strScript);                 
  7.  
  8.   }
  9. }
Rgds,
BTR.
Jan 28 '09 #8
acoder
16,027 Expert Mod 8TB
Yes, that would be the idea if you insist. However, you could improve it by using the checkbox objects, e.g. document.forms[formName].elements["chkselect"], then you'd only need to check that the ID is not the same.

PS. please use [code] tags when posting code.
Jan 28 '09 #9
hey...btreddy
Thats a very good idea.. i was really struggling with the same problem..
Thanks a lot buddy..
Feb 5 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: wooks | last post by:
I have defined a schema with an xsd:choice element for 2 mutually exclusive fields. When both are present I get an error which is good, but what is not so good is the error message which says...
3
by: softengine | last post by:
Can and how do you alter a data view to include a look up field from another data table? The data table of the dataview only has the key, the value I need is in another data table. Can and how...
5
by: WertmanTheMad | last post by:
Ive been playing with this for a few days and thought I might thow it out for seggestions. I have Several Queries that need counts returned The Queries are Mutually Exclusive meaning whatever...
2
by: js | last post by:
I include a asp:RadioButton in an ItemTemplate of a DataGrid like the following. However, the radio buttons are not mutual exclusive where select one will deselect the rest of the radio buttons. I...
2
by: Stimp | last post by:
I'm getting the error: 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive when I try to populate a series of dropdowns... any idea what I could be doing wrong here? ...
8
by: arun | last post by:
Hi Can any one suggest me how to access the mutually exclusive check boxes in a table of 7 rows by 14 columns. Only one can be selected in each row. Other than checking each one with if...
2
by: arun | last post by:
Hi Can any one suggest me how to access the mutually exclusive check box extender in a table of 7 rows by 14 columns. Only one can be selected in each row. Other than checking each one with if...
2
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files...
1
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...
0
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,...
0
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...
0
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...

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.