Click here to Skip to main content
15,867,686 members

How to Check/UnCheck the check box list by retreiving the data from database

ntitish asked:

Open original thread
C#
SqlCommand cmdPickAllAccessebility = DBManager.DataAccess.command();
            
cmdPickAllAccessebility.Parameters.Add(new SqlParameter("@option", SqlDbType.VarChar, 50));
cmdPickAllAccessebility.Parameters["@option"].Value = "PickAllAccessebility";

cmdPickAllAccessebility.Parameters.Add(new SqlParameter("@User_identity", SqlDbType.VarChar, 50));
cmdPickAllAccessebility.Parameters["@User_identity"].Value = rbtnForSelectUser.SelectedValue.ToString();//rbtnForSelectUser.SelectedValue //Session["User_ID"];

string sqlquery2 = "SchoolProc";
DataSet dsetPickAllAccessebility = DBManager.DataAccess.getdata(sqlquery2);

for (int i = 0; i < CheckBoxListForSelectingPrivileges.Items.Count; i++)
{
for (int j = 0; j < dsetPickAllAccessebility.Tables[0].Rows.Count; j++)
{
if (dsetPickAllAccessebility.Tables[0].Rows[j].ToString() == CheckBoxListForSelectingPrivileges.Items[i].Value)
{
CheckBoxListForSelectingPrivileges.Items[i].Selected = true;
}
else
{
CheckBoxListForSelectingPrivileges.Items[i].Selected = false;
}

}
}

this was my code for retrieving the data from database and checked the check box list
but i am not getting any output
i will clearly explain about my problem

i am having a page called administration page.in that page we can see all the user in radio button list(binded all the users to radio button list) and all the privileges in check box list (binded all the privileges to check box list list)

by selecting particular user and selecting particular privileges to that user by checking the check box list that will save in table "User_Access" like below

registration table
user_id | login_id | password 
1       |nitish    | ******

privileges table
access_id | Description | status
1         | admission   |  true
2         | events      |  true
3         |fee-collection| true

User_Access table
user_id |access_id
1       | 2
1       | 3

like the above table i am saving....

what was my problem if next time i selected the same user i want to see the privileges what all ready he is having by retrieving the data from User_Access table

here i am using access_id as data value field for check box list.
in data set i am getting the access_id called as the data value fields of check box list
now what i want is according to the user_access table when we select user_id 1 in admin page it should show the check box list with check box 2,3 should be checked and 1 should be unchecked
Tags: ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900