Solved

Restrict access to Dropdown List values

Posted on 2009-05-15
6
395 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
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 

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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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