Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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
Posted 11-Feb-13 21:03pm
ntitish1.4K
Edited 11-Feb-13 22:01pm
v4
Comments
Maciej Los at 12-Feb-13 3:12am
   
@ntitish,
Do not repost and do not remove questions with answers (as you've done with your previous question and my answer).
Here was my answer: http://www.codeproject.com/Answers/544637/howplustopluscheckplusthepluscheckboxpluslistplusb
ntitish at 12-Feb-13 3:14am
   
sir it was a mistakenly deleted thats why i am again posting....i am really sorry for what i did ...i not even seen the answer of that question....can u send me again if u dont mind...
ntitish at 12-Feb-13 3:16am
   
sir sorry,actually after clicking on that link it is showing my previous question with out answer......
Maciej Los at 12-Feb-13 3:21am
   
I see only: Sorry, the item you requested could not be found. Question and answer doesn't exists!
 
OK, next time you should be more careful ;)
ntitish at 12-Feb-13 3:23am
   
sure sir....are you sending again that answer...
Maciej Los at 12-Feb-13 3:25am
   
Is this phrase true: CheckBoxListForSelectingPrivileges.Items.Count = dsetPickAllAccessebility.Tables[ALL].Rows.Count?
ntitish at 12-Feb-13 3:29am
   
sorry sir,i am not getting what you are asking
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First of all, read my comment.
 
If i understood you well and dsetPickAllAccessebility.Tables[0].Rows is equal to CheckBoxListForSelectingPrivileges.Items.Count, you should change the Selected property based on dsetPickAllAccessebility.Tables[i].Rows[N].Item["status"] value.
for (int j = 0; j < dsetPickAllAccessebility.Tables[0].Rows.Count; j++)
{
    CheckBoxListForSelectingPrivileges.Items[j].Selected = dsetPickAllAccessebility.Tables[0].Rows[j].Item["status"].Value;
}
You don't need the second loop.
  Permalink  
Comments
ntitish at 12-Feb-13 3:41am
   
sir dsetPickAllAccessebility.Tables[0].Rows is not equal to CheckBoxListForSelectingPrivileges.Items.Count
because in user_access table i am saving only checked check boxes data value field but i am not saving unchecked data value field..
ntitish at 12-Feb-13 3:53am
   
is there will be any solution for this sir.
Maciej Los at 12-Feb-13 4:04am
   
Yes, it is. You need to write code based on your criteria. I'll update my answer.
ntitish at 12-Feb-13 4:08am
   
ok sir...
ntitish at 12-Feb-13 4:20am
   
sir while saving the checked check boxes i am saving only data value field not saving the status. user_access table u can see above.
ntitish at 12-Feb-13 5:06am
   
sir u said u will update the answer......i think u r busy,....i am waiting for the solution..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi Dear
 
Plz try this.
string userId = Session["UserId"].ToString();
            foreach (ListItem item in this.chkList.Items)
            {
                if (item.Value != userId)
                {
                    item.Selected = true;
                }
            }
  Permalink  
Comments
ntitish at 13-Feb-13 7:24am
   
sir here i am taking the user_id by selecting the radio button.....not by session[user_id]
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Try this:
//Clear all the selected items
for (int i = 0; i < CheckBoxListForSelectingPrivileges.Items.Count; i++)
{
CheckBoxListForSelectingPrivileges.Items[i].Selected = false;
}
//Iterate all the items and compare them to the returned result set
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]["columnNameOrIndex"].ToString() == CheckBoxListForSelectingPrivileges.Items[i].Value)
{
CheckBoxListForSelectingPrivileges.Items[i].Selected = true;
break;//break the loop if item is matched.
}
//No need for an else block.
}
}
  Permalink  
Comments
ntitish at 14-Feb-13 6:39am
   
thanks sir.......
Zafar Sultan at 14-Feb-13 10:40am
   
Welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,631
1 Sergey Alexandrovich Kryukov 6,345
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140921.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100