本文介绍了如何将选定的复选框文本保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有10个复选框,然后选择了5个.我希望将5个chechbox文本存储在字符串中,并以(,)分隔,然后将该字符串传递给sqlquery以在数据库中插入.....请帮助我..... .... thanx

suppose we have 10 checkbox thn 5 is selected.i want that 5 chechbox text store in string by seperated (,) thn that string pass to sqlquery for insertiojn in database.....please help me.........thanx

推荐答案

<asp:checkboxlist id="CheckBoxList1" runat="server" xmlns:asp="#unknown">
      <asp:listitem text=" checkbox1" value=" checkbox1"></asp:listitem>
      <asp:listitem text=" checkbox2" value=" checkbox2"></asp:listitem>
      <asp:listitem text=" checkbox3" value=" checkbox3"></asp:listitem>
      <asp:listitem text=" checkbox4" value=" checkbox4"></asp:listitem>
      <asp:listitem text=" checkbox5" value=" checkbox5"></asp:listitem>
      <asp:listitem text=" checkbox6" value=" checkbox6"></asp:listitem>
      <asp:listitem text=" checkbox7" value=" checkbox7"></asp:listitem>
      <asp:listitem text=" checkbox8" value=" checkbox8"></asp:listitem>
      <asp:listitem text=" checkbox9" value=" checkbox9"></asp:listitem>
      <asp:listitem text=" checkbox10" value=" checkbox10"></asp:listitem>
     </asp:checkboxlist><br />
     <asp:button id="Button2" runat="server" text="submit" onclick="Button2_Click" xmlns:asp="#unknown" /><br />
     <div id="resdiv" runat="server"></div>



文件后面的代码包含以下代码



And the code behind file contains following code

protected void Button2_Click(object sender, EventArgs e)
{
    string str = string.Empty;
    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
    {
        if (CheckBoxList1.Items[i].Selected)
        {
            if (str.Length > 0)
            {
                str = str + "," + CheckBoxList1.Items[i].Text;
            }
            else
            {
                str = str + CheckBoxList1.Items[i].Text;
            }
        }
    }
    resdiv.InnerHtml = "The Result String is :" + str;

}



在这里,您可以使用该str变量将其存储到数据库中.

希望您知道如何将该值存储在数据库中


最好的



Here you can use that str variable to store into database.

I hope you know how to store that value in database


All the Best


enum OptionSet : System.Int16 {
   None = 0,
   CaseSensitive = 1 << 0, // 1
   Backward      = 1 << 1, // 2
   UseRegEx      = 1 << 2, // 4
   Selection     = 1 << 3, // 8
   //...
}



将其存储在强制转换为SMALLINT的dababase类型中,将其大小写回OptionSet以进行语义操作(业务逻辑),并使用循环和位操作逐位映射到复选框集.我相信您知道如何设置,清除和测试一下...

—SA



Store this thing in dababase type casted to SMALLINT, type case it back to OptionSet for semantic operation (business logic), map to the set of check boxes bit by bit using cycle and bit operations. I trust you know how to set, clear and test a bit…

—SA


这篇关于如何将选定的复选框文本保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:34