判断一下是否为null,为null给个初始值试试

解决方案 »

  1.   

    a.aspx页面
    <script>
    function SetInterestAndLove(chk)
    {
    var arr = '';
    var arrHead = ",";
    arr = document.getElementById("<%=ClientID%>:txtInterestAndLove").value+",";
    if(arr != ",")
    {
    arrHead += arr;
    }
    else
    {
    arr = "";
    }

    var str = chk.value+",";
    if(chk.checked)
    {
    if(arrHead.indexOf(","+str)<0)
    {
    arr += str;
    }
    }
    else
    {
    if(arrHead.indexOf(","+str)>=0)
    {
    arr = arr.replace(str,"");
    }
    }
    if(arr.lastIndexOf(",")>=0)
    {
    arr = arr.substring(0,arr.length-1);
    }
    document.getElementById("<%=ClientID%>:txtInterestAndLove").value = arr;
    }

    </script>
    <input name="checkboxInterestAndLove" id="checkboxInterestAndLove1" runat="server" onclick="SetInterestAndLove(this)"
    type="checkbox" class="hei12" value="艺术"> 艺术 <input type="checkbox" onclick="SetInterestAndLove(this)" id="checkboxInterestAndLove2"
    runat="server" name="checkboxInterestAndLove" class="hei12" value="团体运动"> 团体运动
    <input type="checkbox" id="checkboxInterestAndLove3" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="健身/跑步"> 健身/跑步 <input type="checkbox" id="checkboxInterestAndLove4" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="钓鱼"> 钓鱼 <input type="checkbox" id="checkboxInterestAndLove5" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="骑单车/摩托车"> 骑单车/摩托车<br>
    <input type="checkbox" id="checkboxInterestAndLove6" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="网球"> 网球 <input type="checkbox" id="checkboxInterestAndLove7" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="高尔夫球"> 高尔夫球 <input type="checkbox" id="checkboxInterestAndLove8" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="滑冰/滑雪"> 滑冰/滑雪 <input type="checkbox" id="checkboxInterestAndLove9" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="棋类"> 棋类 <input type="checkbox" id="checkboxInterestAndLove10" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="计算机/网络"> 计算机/网络<br>
    <input type="checkbox" id="checkboxInterestAndLove11" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="游泳"> 游泳 <input type="checkbox" id="checkboxInterestAndLove12" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="电脑游戏"> 电脑游戏 <input type="checkbox" id="checkboxInterestAndLove13" runat="server" onclick="SetInterestAndLove(this)"
    name="checkboxInterestAndLove" class="hei12" value="乒乓球"> 乒乓球 <input type="hidden" id="txtInterestAndLove" name="txtInterestAndLove" runat="server">a.aspx.cs
    protected System.Web.UI.HtmlControls.HtmlInputHidden txtInterestAndLove;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove1;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove2;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove3;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove4;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove5;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove6;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove7;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove8;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove9;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove10;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove11;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove12;
    protected System.Web.UI.HtmlControls.HtmlInputCheckBox checkboxInterestAndLove13;
    /// <summary>
    /// 兴趣与爱好
    /// </summary>
    public string InterestAndLove
    {
    get
    {
    return txtInterestAndLove.Value;
    }
    set
    {

    txtInterestAndLove.Value = value;
    }
    } private void Page_Load(object sender, System.EventArgs e)
    {
    if (InterestAndLove != "")
    {
    SetCheckBox(checkboxInterestAndLove1);
    SetCheckBox(checkboxInterestAndLove2);
    SetCheckBox(checkboxInterestAndLove3);
    SetCheckBox(checkboxInterestAndLove4);
    SetCheckBox(checkboxInterestAndLove5);
    SetCheckBox(checkboxInterestAndLove6);
    SetCheckBox(checkboxInterestAndLove7);
    SetCheckBox(checkboxInterestAndLove8);
    SetCheckBox(checkboxInterestAndLove9);
    SetCheckBox(checkboxInterestAndLove10);
    SetCheckBox(checkboxInterestAndLove11);
    SetCheckBox(checkboxInterestAndLove12);
    SetCheckBox(checkboxInterestAndLove13);
    }

    } private void SetCheckBox(System.Web.UI.HtmlControls.HtmlInputCheckBox CheckBox)
    {
    string strNewCarPriceValue = ","+InterestAndLove+",";

    if (strNewCarPriceValue.IndexOf(","+CheckBox.Value+",")>=0) 
    {
    CheckBox.Checked = true;;
    }
    else
    {
    CheckBox.Checked = false;
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
      

  2.   

    我考  你那个 信息保持周期 还是可以多选的啊    如果是单选就好办了, 用个switch就搞定了
      

  3.   

    这是写的一个ascx你可以把他改成你所要的