如何在数据库中保存复选框选中的值 [英] how to save the checkbox selected value in database

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

问题描述

嗨朋友们,



我正在使用asp.net c#和SQLSERVER 2005.



on我的网页我有gridview with checkboxes,用户只能从gridview中的复选框列表中选择一个复选框。



在这个gridview中我有3列作为UserName,Password,Status



我也在gridview外提交按钮。



所以我的要求是:

----------------------



当用户选择一个复选框并点击时提交按钮。在数据库表中,它必须插入status = 1



这必须在chckbox选中并单击提交按钮时发生。



请帮助我



谢谢。

Hi friends,

am working on asp.net c# and SQLSERVER 2005.

on my webpage i have gridview with checkboxes, user can select only one checkbox from list of checkboxes inside gridview.

In this gridview i have 3 columns as UserName,Password,Status

and also i have submit button outside gridview.

So my requirement is :
----------------------

when user select one checkbox and click on submit button. In Database table it must insert status =1

This must happen when chckbox slected and submit button clicked.

Please can you help me

Thanks.

推荐答案

请查看获取复选框详细信息的想法来自gridview的每一行

Please see the idea to get checkbox details from each row of gridview
foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox cb = (CheckBox)row.FindControl("CheckBoxID");
                if (cb.Checked)
                {
                //write your code
                }
                else {
                //write your code
                }
            }


看到我不知道你的确切代码,但我告诉你如何做到这一点



foreach(GridView1.Rows中的GridViewRow行)

{

CheckBox cb =(CheckBox)row.FindControl(CheckBoxID);

HiddenField hdnid =(HiddenField)row.FindControl(hdnId);

//将您的数据库主键ID绑定在隐藏字段中,并在此处找到它

if(cb.Checked)

{

//编写代码

int ID = Convert.ToInt32(hdnid.Value) ;

string query =update tableName set status = 1其中id =+ ID;

dal.UpadateTable(查询);

}

else {

//编写代码

}

}
see i couldn't know your exact code but i am showing you how to do it

foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBoxID");
HiddenField hdnid =(HiddenField) row.FindControl("hdnId");
//Bind your database primary key id in a hidden field, and find it here
if (cb.Checked)
{
//write your code
int ID = Convert.ToInt32(hdnid.Value);
string query = "update tableName set status=1 where id="+ID;
dal.UpadateTable(query);
}
else {
//write your code
}
}


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

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