mail not delivering to selected values in checkboxlist

Posted by Parthibansk under ASP.NET on 8/29/2013 | Points: 10 | Views : 1094 | Status : [Member] | Replies : 9
got a mailing list binded to a checkboxlist..

when i cilck button only 1st value in checkboxlist is delivered mail not the rest..

here is my code..

string message = "";
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected == true)
{
message += item.Value;
}
}

how to resolve




Responses

Posted by: Allemahesh on: 8/29/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Parthibansk,

Just try this code:-

string message = "";
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected == true)
{
message += item.Value;
break;
}
}

Happy Coding

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
string message = "";


for(int i=0; i < CheckBoxList1.Items.Count; i++)
{
if(CheckBoxList1.Items[i].Selected)
message += CheckBoxList1.Items[i].Value + "; ";
}


References:
http://forums.asp.net/t/1674923.aspx/1
http://stackoverflow.com/questions/8815963/how-to-get-selected-item-in-checkboxlist-in-asp-net
http://stackoverflow.com/questions/9523263/how-can-i-get-the-checkboxlist-selected-values-what-i-have-doesnt-seem-to-work

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 8/29/2013 [Member] Starter | Points: 25

Up
0
Down
tried above code only 1st selected value in checkboxlist is getting mail

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 8/29/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Parthibansk,

I thing it is working.
Can you click on Mark As Answer. So that it will help some else.

Happy Coding

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 8/29/2013 [Member] Starter | Points: 25

Up
0
Down
not working tried.. 1st selected value only getting mail..

see my mail code

Msg.To.Add(CheckBoxList1.SelectedItem.text)

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
I think you are asking about multiple selection
string message = "";

for(int i=0; i < CheckBoxList1.Items.Count; i++)
{
if(CheckBoxList1.Items.Selected)
message += CheckBoxList1.Items.Value + "; ";
}

this is for multiple selection...
Refer http://stackoverflow.com/questions/9523263/how-can-i-get-the-checkboxlist-selected-values-what-i-have-doesnt-seem-to-work

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 8/29/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Parthibansk,
I got you problem.

Change the mail code as below:-

for(int i=0; i < CheckBoxList1.Items.Count; i++)
{
if(CheckBoxList1.Items.Selected)
message += CheckBoxList1.Items.Value + "; ";
}

Msg.To.Add(message.ToString());

Happy Coding.

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Have you solved the issue which posted here...?
If yes, mark it as answer

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 8/31/2013 [Member] Starter | Points: 25

Up
0
Down
not solved..

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response