如何在数据库中保存复选框列表的多个值? [英] How Can I Save Multiple Value Of Check Box List In Database?

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

问题描述

我有一个动态复选框列表哪个值来自数据库表(名为T_Hygene)。现在我想将一些选定值保存到数据库中另一个名为(T_Transaction)的表中。我可以这样做吗?

i have a dynamic check-box list Which value comes from database table (named T_Hygene). now i want to save some selected value to another table named (T_Transaction)in the database.how can i do this?

推荐答案

假设CBLList是你的复选框,所以你必须首先获取已选中的复选框的所有值。必须保存在database.Lelow中的表中,该代码将为您提供字符串变量chkbox_selected中所有已选中复选框的逗号分隔值。



string chkbox_selected;

for(int i = 0; i< CBLList.Items.Count; i ++)

{

if(CBLList.Items [i] .Selected == true)

{

chkbox_selected + = CBLList.Items [ i] .Value +,;

}

}

chkbox_selected = chkbox_selected.Remove(chkbox_selected.Length - 1,1);



现在在chkbox_selected中,您将以逗号分隔模式选中复选框的所有值。现在你可以相应地使用这些。



谢谢
Suppose CBLList is your checkboxlist, so you have to first get all the values of checkboxs which are checked & have to be save in table in database.Below is the code which will give you comma separated values of all the checked checkboxes in the string variable chkbox_selected.

string chkbox_selected;
for (int i = 0; i < CBLList.Items.Count; i++)
{
if (CBLList.Items[i].Selected == true)
{
chkbox_selected += CBLList.Items[i].Value + ",";
}
}
chkbox_selected = chkbox_selected.Remove(chkbox_selected.Length - 1, 1);

Now in chkbox_selected you have all the checked value of checkbox in comma separated mode. Now you can use these accordingly.

Thanks


string sno = "";
int y = 0;
for (int i = 0; i < chk.Items.Count; i++)
{
    if (chk.Items[i].Selected)
    {
        if (y == 0)
        {
            sno = chk.Items[i].Value;
        }
        else
        {
            sno += "," + chk.Items[i].Value;
        }
        y++;
    }
}


试试这样,

Try like this,
string lst = "";
foreach (ListItem lists in Your_DynamicCheckBoxID.Items)
{
lst = lists.ToString() + "," + lst;
string StringAdd= lst.ToString();
int comma = StringAdd.LastIndexOf(',');
string FinalString= StringAdd.Substring(0, comma);   
}



此FinalString返回动态复选框列表中的所有选定文本。您可以使用插入查询将此字符串值存储到表(T_Transaction)。

如果你想单独存储每个选定的值,只需省略StringAdd,FinalString并将字符串lst值传递给你的数据库。


This FinalString Returns all selected text from your dynamic check box list.You can store this string value to your Table (T_Transaction) by using insert query.
If you want to store each selected value seperately,just omit StringAdd, FinalString and just pass string lst value to your database.


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

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