Consider that 2nd checkbox is checked, hence all other check boxes are deactive.
Then how come it possible to check other checkboxes...?
If we need to check other checkbox, we need to uncheck the already checked checkbox, so now all checkbox comes active while mean all checkbox again enabled, so we can check the other checkbox, now this checkbox become enabled rest of became disabled.
What is my needed idea is, output is needed is only one checkbox should selected.
sarathi125
Star
13599 Points
2691 Posts
Re: New to ASP.DOT
Dec 26, 2012 01:56 PM|LINK
Hi,
Consider that 2nd checkbox is checked, hence all other check boxes are deactive.
Then how come it possible to check other checkboxes...?
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
n2adn_India
Member
15 Points
75 Posts
Re: New to ASP.DOT
Dec 26, 2012 02:04 PM|LINK
If we need to check other checkbox, we need to uncheck the already checked checkbox, so now all checkbox comes active while mean all checkbox again enabled, so we can check the other checkbox, now this checkbox become enabled rest of became disabled.
What is my needed idea is, output is needed is only one checkbox should selected.
msmk
Participant
776 Points
158 Posts
Re: New to ASP.DOT
Dec 26, 2012 02:09 PM|LINK
Refer to my reply on your other thread:
http://forums.asp.net/t/1868662.aspx/1?ReEnable+Checkbox+in+GridView
In the future, please don't create duplicate threads for the same question.
Thank you.
sarathi125
Star
13599 Points
2691 Posts
Re: New to ASP.DOT
Dec 26, 2012 02:11 PM|LINK
Hi,
Ok then try like the following
protected void cbGV_CheckedChanged(object sender, EventArgs e) { //gets the current checked checkbox. CheckBox activeCheckBox = sender as CheckBox; BOOL flag = false; CheckBox selectedCheckBox; foreach (GridViewRow gvr in GridView1.Rows) { //this code is for finding the checkboxes in the gridview. CheckBox checkBox = ((CheckBox)gvr.FindControl("cbGV")); if (checkBox.Checked==true && flag==false) { flag = true; selectedCheckBox = checkBox; } else { if (checkBox != selectedCheckBox) { checkBox.Enabled = false; checkBox.Checked = false; } } }Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
n2adn_India
Member
15 Points
75 Posts
Re: New to ASP.DOT
Dec 26, 2012 02:54 PM|LINK
I am from C# background mate,
Can you describe this in C#
sarathi125
Star
13599 Points
2691 Posts
Re: New to ASP.DOT
Dec 26, 2012 03:02 PM|LINK
Hi,
It is the line of code which is used to identify the checkbox which is clicked in the gridview...
Dim activeCheckBox As CheckBox = TryCast(sender, CheckBox)
this is the vb.net equal for the same.
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
msmk
Participant
776 Points
158 Posts
Re: New to ASP.DOT
Dec 26, 2012 03:19 PM|LINK
This is the way to do it in C#
n2adn_India
Member
15 Points
75 Posts
Re: New to ASP.DOT
Dec 26, 2012 03:48 PM|LINK
Sorry I am confused...
Thanks mate
n2adn_India
Member
15 Points
75 Posts
Re: New to ASP.DOT
Dec 26, 2012 03:50 PM|LINK
Sorry I am confused...I am a beginner of dotnet,
Thanks mate
msmk
Participant
776 Points
158 Posts
Re: New to ASP.DOT
Dec 26, 2012 04:03 PM|LINK
'sender' refers to the control that 'sent' the event. It is passed into the method as a parameter:
protected void cbGV_CheckedChanged(object sender, EventArgs e)
So the code you are confused about takes the control stored in 'sender', casts it into a checkbox object, and stores it in a variable, activeCheckBox.
CheckBox activeCheckBox = (CheckBox)sender;