如何根据数据库记录设置选中的复选框? [英] How to set checked Checkbox based on database record?

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

问题描述

我想从数据库中循环订阅列表.

同时,我循环特定用户的订阅请求.

例如,在订阅列表中,有几个项目,

系统分析师
系统开发人员
系统管理员
系统测试仪

用户在订阅列表中订阅了其中的2个,

系统管理员
系统测试仪

在循环中,我将循环一个带有复选框列的表以显示所有订阅值.

我在这里遇到问题.

我要在用户订阅该项目时使该复选框处于已选中"状态.

例如,表的结果应已选中复选框"2".

但是,我不知道实现我的逻辑的算法.

I want to loop the subscription list from the database.

At the same time, I loop the specific user''s subscription request.

For example, in the subscription list, there are several items, says

System Analyst
System Developer
System Manager
System Tester

In the subscription list, the user subscribed 2 of them, says

System Manager
System Tester

In the looping, I will loop a table with a checkbox column to show all the subscription value.

I encounter a problem here.

I want to make the checkbox "checked" while the user has subscribed the item.

For example, the result of table should have "checked" 2 of the checkbox.

However, I don''t know the algorithm to implement my logic.

Can anyone kindly provide some hints for me to realize this?

推荐答案



试试这个
Hi,

try this
  if(dt.rows[0][3].tostring().startswith("Checked"))
{
 Checkbox2.Checked=true;
}
else
{
Checkbox2.Checked=false;
}



例如

您的表中有类似
的列
带有UserID,Analyst,Developer,Manager,Tester列的SubscribeTab

然后,如果用户只有Manager和Tester,则

您可以根据ID从数据库检索数据,然后结果表包含

例如
231,No,No,Checked,Checked

所以您可以使用上面的方法.

您可以按照相同的方式来存储

最好的



for e.g

your table has columns like

SubscribeTab with columns UserID,Analyst,Developer,Manager,Tester

Then If user has only Manager and Tester then

you can retrieve data from database based on id then your result table contains

for e.g
231,No,No,Checked,Checked

so just you can use above method for that.

you can follow same meethod for storing also

All the Best


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

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