I want to sort my searching process, currently i need to check everyone checkbox, I want to know that m is there a sort way by which we can minimize our checking process, Is there a control like groupbox by which we can take all these checkbox under the group, and check if group item is edited or not, if edited then we take a loop on it, if not edited then no need of loop, Please if you have an idea, then tell me.
8 Answers
Know the answer? Post it. Somebody with the same question will find it here.
VulpesRank #55 · 29.2K reputationPosted Mar 20, 2011, 12:57 AM EDT
✓ Accepted answer0
An easy way to determine whether any checkboxes are selected is to see if the SelectedIndex property is > -1.
So you could:
if(checkboxlist1.SelectedIndex > -1)
{
for (int i=0; i
{
if (checkboxlist1.Items[i].Selected)
{
// Do what ever you want with selected items.
}
}
}
The 'for' statement won't then run if nothing is selected.
0
VulpesRank #55 · 29.2K reputationPosted Mar 16, 2011, 1:18 AM EDT
0
That looks like a situation where you could use RadioButtons rather than CheckBoxes as I imagine a key executive could only fall under one of these categories at any given time.
RadioButtons which are all within the same container (for example the form itself, a panel or groupbox) act together as a group - when you check one, the others automatically uncheck.
If you put the RadioButtons in an array, then you could iterate through them using a for loop to see which one is currently checked.This is not as much code as examining each one individually.
0
Vikas AhlawatRank #2,648 · 525 reputationPosted Mar 16, 2011, 4:04 AM EDT
//This event will help you to only get the values when the any checkbox is checked
Code
void Check_Clicked(Object sender, EventArgs e)
{
Message.Text = "Selected Item(s):
";
// Iterate through the Items collection of the CheckBoxList
// control and display the selected items.
for (int i=0; iif (checkboxlist1.Items[i].Selected)
{
// Do what ever you want with selected items.
}
}
}
Hope your code get minimized by this.
Don't forget to mark as answer.
Thanks
0
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 19, 2011, 3:45 AM EDT
0
hi vikas,
i received that you have marked it as answer but it didn't try again as a favour back ;))
VulpesRank #55 · 29.2K reputationPosted Mar 20, 2011, 12:57 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 16, 2011, 1:18 AM EDT
RadioButtons which are all within the same container (for example the form itself, a panel or groupbox) act together as a group - when you check one, the others automatically uncheck.
See here (http://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton.aspx) for further details.
If you put the RadioButtons in an array, then you could iterate through them using a for loop to see which one is currently checked.This is not as much code as examining each one individually.
Vikas AhlawatRank #2,648 · 525 reputationPosted Mar 16, 2011, 4:04 AM EDT
Keyexecutive can be more then one
like this
http://www.fundoodata.com/products/advance_search.php
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 16, 2011, 4:19 AM EDT
There's a control named CheckBoxList in asp.net. you can use it for getting all the checked and unchecked items.
intialize it by any collection
"checkboxlist1" AutoPostBack="True" CellPadding="5" CellSpacing="5" RepeatColumns="2" RepeatDirection="Vertical" RepeatLayout="Flow" TextAlign="Right" OnSelectedIndexChanged="Check_Clicked" runat="server"> Item 1 Item 2 Item 3 Item 4 Item 5 Item 6ListItem liTemp = new ListItem("Test","01");
checkboxlist1.Items.Add(liTemp);
and use the below code to get the checked items
//This event will help you to only get the values when the any checkbox is checkedAmit ChoudharyRank #145 · 15.8K reputationPosted Mar 19, 2011, 3:45 AM EDT
i received that you have marked it as answer but it didn't try again as a favour back ;))
Thanks.
Vikas AhlawatRank #2,648 · 525 reputationPosted Mar 19, 2011, 10:43 PM EDT
I m also using this checkboxs list.
but i want to know that, if no list item is selected the
we don't need to run this for loop.
Suthish NairRank #92 · 22.8K reputationPosted Mar 20, 2011, 7:40 AM EDT
TextAlign="Right" runat="server">
using System.Collections.Generic;
protected void Button1_Click(object sender, EventArgs e)
{
//IEnumerable
// where item.Selected
// select item.Text;
IEnumerable
where item.Selected
select int.Parse(item.Value);
Response.Write("Selected Value/Text
");
foreach (var item in allChecked)
{
Response.Write(item + "
");
}
allChecked = null;
}
Vikas AhlawatRank #2,648 · 525 reputationPosted Mar 20, 2011, 7:18 PM EDT
Thanks for your replies
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts