如何将多个复选框项列表发送到类

时间:2012-07-25 20:55:36

标签: c# asp.net

我想将所有选中的复选框项目发送到课程中如何发送它。如果我使用check1.selectedvalue/item它只发送一个。我该怎么做

protected void check1_SelectedIndexChanged(object sender, EventArgs e)
{
   for (int z = 0; z < check1.Items.Count; z++)
   {
      if (check1.Items[z].Selected)
      {
         string checking = "\u2022" + check1.Items[z].Text ;
      }
   }

   Mail emailsystem = new Mail();
   emailsystem.GetEmail(comment.Text, StatusList.SelectedValue, check1.SelectedValue);
}

2 个答案:

答案 0 :(得分:0)

假设您使用的是CheckBoxList,则可以执行以下操作:

protected void check1_SelectedIndexChanged(object sender, EventArgs e)
{
    string result = string.Empty;

    foreach (ListItem listitem in check1.Items)
    {
        if (listitem.Selected)
        {
           result += ("\u2022" + listitem.Text);
        }
    }
    Mail emailsystem = new Mail();
    emailsystem.GetEmail(comment.Text, StatusList.SelectedValue, result);
}

答案 1 :(得分:0)

您需要连接已选中复选框的文本并将其传递给您的emailSystem

protected void check1_SelectedIndexChanged(object sender, EventArgs e)
{
   string checking = "";
   for (int z = 0; z < check1.Items.Count; z++)
   {
      if (check1.Items[z].Selected)
      {
         checking += "\u2022" + check1.Items[z].Text;
      }
   }

   Mail emailsystem = new Mail();
   emailsystem.GetEmail(comment.Text, StatusList.SelectedValue, checking );
}