如何从复选框列表构建字符串 [英] How to Build String from Checkbox List

查看:88
本文介绍了如何从复选框列表构建字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索应用程序有2页并使用母版页。许多asp.net控件驻留在默认页面上,我需要将他们选择的值添加到结果页面上的标签。我正在使用会话变量将字符串内置(critString)从控件值传递到第二页。但是,使用下面的代码,它只是跳转&在foreach的第一步。



I have a search app that has 2 pages and uses a master page. A number of asp.net controls reside on the default page and I need to get their selected values to a label on the results page. I am using a session variable to pass the string built (critString) from the control values to the second page. However with the code below it simply jumps& over the 1st step of the foreach.

public void doStuff()
      {
          var props = new[]{
              "txtFacility", "txtCity", "txtZip",
              "rblFacilityType", "cboSubs", "ddlbCounty",
              "ddlStar", "cblProgramOp", "cblAgeCat",
              "cblTrans"};
          foreach (var v in props)
          {
              if (FindControl(v) != null)
                  {
                      switch (v.Substring(0, 3))
                      {
                          case "cbl":
                              critString += fillcbxl((CheckBoxList)FindControl(v));
                              break;
                          case "ddl":
                              critString += fillddl((DropDownList)FindControl(v));
                              break;
                          case "cbo":
                             critString += fillcbx((CheckBox)FindControl(v));
                              break;
                          case "rbl":
                              critString += fillrbl((RadioButtonList)FindControl(v));
                              break;
                          default:
                              critString += fillTextBox((TextBox)FindControl(v));
                              break;
                      }
                  }
              }
          }





我不是此时发送方法调用是因为如果不让它工作,我就无法访问它们。我认为这可能是一个错误的FindControl进程,因为涉及到master.page。但是,如果没有选中复选框,它会评估null(注意选定的场景)。



I am not sending the method calls at this time because I can't get to them without getting this to work. I figure it maybe a errant FindControl process given there is a master.page involved. But then it could be that with no checks box selected it evaluates null (noting selected scenario).

推荐答案

使用stringbuilder



http://www.dotnetperls.com/stringbuilder [ ^ ]



using stringbuilder

http://www.dotnetperls.com/stringbuilder[^]

// Declare a new StringBuilder.
StringBuilder builder = new StringBuilder();
builder.Append(fillcbxl((CheckBoxList)FindControl(v)));


这篇关于如何从复选框列表构建字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆