?
Solved

Restrict access to Dropdown List values

Posted on 2009-05-15
6
Medium Priority
?
400 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 1000 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
Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

 

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 1000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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