Solved

Restrict access to Dropdown List values

Posted on 2009-05-15
6
390 Views
Last Modified: 2013-11-26
Hi and thanks for taking a moment. I need to know how to restrict the availability of  a dropdown value from a dropdown list control. I want to do something like what is below, however in c# this is invalid.  All of the original values for the dropdown list control are populated from a database. I need to filter them at the code level now. Any help greatly appreciated.

if (lblDept.Text == "Quality Assurance" || lblDept.Text == "Information Technology")
        {
 
            ddlComplaintstatus.Items[0].Visible = false;
          }

Open in new window

0
Comment
Question by:jazzcatone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:jhabas_ons
ID: 24397337
Have you considered just removing the item from the list if they are not allowed access?
0
 
LVL 2

Accepted Solution

by:
jhabas_ons earned 250 total points
ID: 24397426

      if (lblDept.Text == "Quality Assurance" || lblDept.Text == "Information Technology")
      {
        ddlComplaintstatus.Items.RemoveAt(0);
      }

Open in new window

0
 

Author Comment

by:jazzcatone
ID: 24397450
Hi and thanks for your reply. Certain people may need to access those values however. I know how to write the conditional ( the "if" statement). Just can't figure out how to isolate the particular value and make it invisible.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:jazzcatone
ID: 24397486
Sorry. I didn't see your code sample you provided. I understand your comment now.
0
 
LVL 2

Expert Comment

by:jhabas_ons
ID: 24397599
If you will not know where the item is located in the list you may be able to do something like the following:
ListItem li = ddlComplaintstatus.Items.FindByValue("Pending");
if (lblDept.Text == "Quality Assurance" || lblDept.Text == "Information Technology")
  ddlComplaintstatus.Items.Remove(li);

Open in new window

0
 
LVL 2

Assisted Solution

by:krishrr
krishrr earned 250 total points
ID: 24397627
You can add items manually with for loop to dropdown from dataset or datareader instead of directly binding them using 'DataSource'.

Method 1:
DropDownList.Items.Add("value")

Method2 :
To add items to the DropDownList, along with a Value Field, you can do something like this (the second item is the one that populates the Value:
ddl2.Items.Add(New ListItem("Item 1", "1"))

OR

You can remove the items after binding with DataSource like this:

Method 1:
ddl.Items.RemoveAt(index)

Method2:
ListItem li = dropdownlist.Items.FindByValue(strValue);
if(li != null)
    dropdownlist.Items.Remove(li);
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

731 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question