本文介绍了从ASP.NET中的SQL中选择CheckBoxList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我使用SQL困住了我的asp.net webform。我(让我为你简化)2个表:



table1有1列,名为(ID),数据类型为'int'。它现在有61行,值为1 ... 61。任何时候我想增加可能的值,我必须在SQL中添加它而不是在ASP.NET代码中。这很简单。 Table1现在看起来像这样:



ID |

1 |

2 |







60 |

61 |



table2有2列,名为(Customer和Code),它们都有'int'数据类型。我这里只使用INSERT命令,稍后会说明原因。




我有一个CheckBoxList,它有多个CheckBoxes和多行有table1(在这种情况下是61)。我通过SqlDataReader获取这些复选框。它正在工作,我可以看到所有61个复选框。



现在有问题的部分出现了:

我将INSERT命令输入table2,我必须在Code列中使用1到61之间的任何值。所以现在我在表2中有这些数据:



客户|代码

155 | 13

160 | 61

155 | 48



当我在我的网络表格中选择客户155时,我想在CheckBoxList中显示所有61个CheckBox,但只应检查那两个CheckBoxes(13和48) ),剩下的应该保持不受控制。



我没有找到任何解决方案。我只找到那个,只有那两个CheckBox会被看到。但这对我不利。我必须为每个客户选择未经检查的盒子。



感谢您的帮助。



Attila

Dear All,
I'm stuck with my asp.net webform using SQL. I have (let me simplify it for you) 2 tables:

table1 has 1 column, named (ID) and data type of 'int'. It has now 61 rows with values of 1...61. Anytime I want to increase the possible values, I have to add it in SQL and not in ASP.NET code. It's simple. Table1 looks like this now:

ID |
1 |
2 |
.
.
.
60 |
61 |

table2 has 2 columns, named (Customer and Code), both of them have data type of 'int'. I use only INSERT commands here, later will be described why.


I have a CheckBoxList, that has as many CheckBoxes as many rows has the table1 (in this case it is 61). I get these checkboxes via SqlDataReader. It is working, I can see all the 61 checkboxes.

The problematic part is now coming up:
I make an INSERT command into table2, I have to use any value between 1 and 61 in the Code column. So now I have these kind of data in table2:

Customer | Code
155 | 13
160 | 61
155 | 48

When I choose Customer 155 on my webform, I would like to show all the 61 CheckBoxes in the CheckBoxList but only those 2 CheckBoxes should be checked (13 and 48), the rest should be stay unchecked.

I didn't find any solution for this. I found only that one, when only those 2 CheckBoxes would be seen. But it is not good for me. I have to see the unchecked boxes for every customer I may choose.

Thanks for your help.

Attila

推荐答案


while (dr.Read())
            {
                ListItem li = hibakodCheckBoxList.Items.FindByValue(dr[0].ToString());
                if (li != null)
                {
                    li.Selected = true;
                }

            }


这篇关于从ASP.NET中的SQL中选择CheckBoxList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 08:40