I am running through a set of data, which will populate a CheckBoxList. I want to display all the items in the list but certain ones will be disabled as they don't qualify (their status equals Inactive). How do I set an item to disabled (Enabled = false) in the code behind like this?
if (node.SelectSingleNode("Status") == "Inactive")
{
customerList.Items.Add(new ListItem(displayName, displayValue)); // DISABLED
}
else
{
customerList.Items.Add(new ListItem(displayName, displayValue)); // ENABLED
}
if (node.SelectSingleNode("Status") == "Inactive")
{
customerList.Items.Add(new ListItem{Name=displayName, Value= displayValue, Enabled= false}); // DISABLED
}
else
{
customerList.Items.Add(new ListItem(displayName, displayValue)); // ENABLED
}`
Haven't tried it but this may work:
customerList.Items.Add(new ListItem(displayName, displayValue)); // DISABLED
ListItem li = customerList.Items.FindByValue(displayValue);
li.Enabled = false;
UPDATED to use FindByValue
Related
So i am trying to do the following in order to style (StaticSelectedStyle-CssClass and DynamicSelectedStyle-CssClass) the selected child item AND its parent. The following code causes only the parent to style:
private bool SetSelectedMenuItem(MenuItemCollection menuItems)
{
foreach (MenuItem item in menuItems)
{
string url = ResolveUrl(item.NavigateUrl);
string pageUrl = Request.RawUrl;
if (pageUrl.Equals(url))
{
item.Selected = true;
if (item.Parent != null)
{
item.Parent.Selected = true;
}
return true;
}
if (SetSelectedMenuItem(item.ChildItems))
{
return true;
}
}
return false;
}
Is it even possible to have a child and its parent item to have their selected value set to true?
Any help to get this working would be great!
It's not possible. Take a look at documentation on the Selected property. The last line of the Remarks section says this:
Only one menu item can be selected at a time in the Menu control.
I am using the Tab_SelectionChanged event of TabControl in WPF. It contains 3 tab items. I have to restrict the user to navigate to other tabs i.e Settings and Schedule while work is in-progress on the home tab. While using the event i am facing an issue i.e. If i clicked on settings tab it shows me a popup "You cannot navigate while work is in progress" and when i clicked on schedule tab after clicking on settings tab it shows me the same popup twice. The reason behind this is the Settings tab remains selected.Here is my code for this:
private void tabMHPC_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
TabControl tab = (TabControl)sender;
if (tab.SelectedIndex != -1)
{
if (tab.SelectedIndex != 4 && tab.SelectedIndex != 1 && tab.SelectedIndex != 0)
{
if (scanStatus == "fixing")
{
MessageBox.Show(ApplicationInfo.ApplicationName + " is still busy in fixing issues.Please let the fixation complete.", ApplicationInfo.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Information);
homeTab.IsSelected = true;
}
else
{
MessageBox.Show(ApplicationInfo.ApplicationName + " is still busy scanning issues.Please stop it before you leave the Home tab.", ApplicationInfo.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Information);
homeTab.IsSelected = true;
}
}
else if (tab.SelectedIndex == 0)
{
}
}
}
I want that previous tab item isSelected property gets false when i move on other tabitem.
Instead of handling the SelectionChanged event, you should data bind a property of a suitable type to the TabControl.SelectedItem property:
<TabControl SelectedItem="{Binding YourSelectedItemProperty}" ... />
When you do this, you will then be able to stop the TabItem being changed:
public YourDataType YourSelectedItemProperty
{
get { return yourSelectedItemProperty; }
set
{
if (isOkToChangeTabItem)
{
yourSelectedItemProperty = value;
NotifyPropertyChanged("YourSelectedItemProperty");
}
}
}
The final part of the solution is to set the isOkToChangeTabItem variable to true or false depending on whether it is OK for the user to change the selected TabItem or not.
I had a problem about Menu. I add a MenuItem in asp.net. I'm using c#. I want to disable Menu Parents and Children with user's permission.
There are 3 users which are "User","Power-User" and "BT_User". "User" have worst permission and "BT_User" have best.
How can I do that? Can anyone answer me?
Implemente your logic from here..
if(UserType == "Power-User")
{
MenuItem mnuItem = Menu1.FindItem("MenuOption"); // If delete a specific item
//to remove
Menu1.Items.Remove(mnuItem);
//to disable and not remove
mnuItem.Enabled = false;
}
if (UserType == "BT_User")
{
Your other logic
}
try this
if (UserType == "Power-User")
{
Menu1.Items.Find("MenuToDelete1", true)[0].Enabled = false;
Menu1.Items.Find("MenuToDelete2", true)[0].Enabled = false;
//or
Menu1.Items.Remove(Menu1.FindItem("MenuToDelete"));
Menu1.Items.Remove(Menu1.FindItem("MenuToDelete2"));
}
if (UserType == "BT_User")
{
Menu1.Items.Find("DeletedItem1", true)[0].Enabled = true;
Menu1.Items.Find("DeletedItem2", true)[0].Enabled = true;
MenuItem item1 = new MenuItem();
item.Text = "DeletedItem1";
MenuItem item2 = new MenuItem();
item.Text = "DeletedItem2";
//or
menuStrip1.Items.Insert(index1, item1);
menuStrip1.Items.Insert(index2, item2);
}
Just leverage the Enabled property of the MenuItem. There is not enough information to tell you how to build the logic around it, but when you want to disable one just do this:
menuItem.Enabled = false;
One thing to note here is that you wouldn't need to continue disabling any children when you disable a parent because with Enabled set to false it's not going to be allowed to fly out any children.
From the MSDN documentation for the Enabled property:
Gets or sets a value that indicates whether the MenuItem object is enabled, allowing the item to display a pop-out image and any child menu items.
I have multiple check boxes on my GUI application that enables auto update for each object of the same type. So if the checkbox is checked, the isautoupdate property is set to true else set to false. I have a button that needs to enable/disable auto update on all checkboxes. How do I go about checking if isautoupdate property of all the objects is set to true or false.
my current implementation is using a foreach loop that iterates through each object and checks if the isautoupdate is set to true or false but I get a toggle effect where if some checkboxes are checked it will uncheck them and vise versa.
in .cs
foreach (MxL_GUI_ChannelSettingAndStatusItem item in theGUIManager.theDevice.channelCollection)
{
if (!item.IsAutoUpdated)
{
item.IsAutoUpdated = true;
}
else
{
item.IsAutoUpdated = false;
}
}
If you don't want your slave checkboxes to toggle then don't write code that toggles them. Instead, check the IsChecked property of the master checkbox and apply the value to all IsAutoUpdated properties of your items:
foreach (MxL_GUI_ChannelSettingAndStatusItem item in ...)
{
item.IsAutoUpdated = masterCheckbox.IsChecked.Value;
}
I'm not sure if I understand you requirement exactly. If you want to detect if all items are set to true or false then use:
var items = theGUIManager.theDevice.channelCollection;
// If you need to know if for all items IsAutoUpdated = true
bool allChecked = items.All(item => item.IsAutoUpdated);
// If you need to know if they're all false
bool noneChecked = !items.Any(item => item.IsAutoUpdated);
Then update your items, e.g:
foreach(var item in items) { item.IsAutoUpdated = !allChecked; }
I have created a web page "Default.aspx" in which I have taken fields:
First Name, Last Name, Account Titling, Titling(radio button list), AccountNumber and AccountFormat
under the "Default.aspx" page, I have used a radio button list also, whose values are Yes and No. If I choose Yes, then the following fields visibility should set to false:
First Name, Last Name
If I choose "NO", then the following fields visibility should set to true:
Account Titling, Account number
For this, I have written the below Java Script code in "Default.aspx"
function EnableDisableTaxID() {
if (document.getElementById("<%=rdOpeningSubAccount.ClientID %>") != null) {
var openSubAccountList = document.getElementById('<%= rdOpeningSubAccount.ClientID %>');
var fbo1RadioList = document.getElementById('<%=fbo1RadioButtonList.ClientID %>').value;
var isOpenSubAccount;
if (openSubAccountList != null) {
var openSubAccount = openSubAccountList.getElementsByTagName("input");
for (var i = 0; i < openSubAccount.length; i++) {
if (openSubAccount[i].checked) {
isOpenSubAccount = openSubAccount[i].value;
alert("Print" + isOpenSubAccount);
}
}
}
alert(typeof(isOpenSubAccount));
if (isOpenSubAccount == 'true') {
FirstName.visible = true;
LastName.visible = false;
AccountTitling.visible = true;
lblFirstName.visible=false;
lblLastName.visible=false;
}
else if (isOpenSubAccount == 'false') {
AccountTitling.visible = true;
AccountNumber.visible = false;
lblAccountTitling.visible = true;
lblAccountNumber.visible = false;
}
}
}
However, I am getting the required value from the Radio button list, however, when I go to check if the selected value of the radiobuttonlist is true, then the code above does not work. I dont know what am I missing. I know that directly using the below code will not work:
if (isOpenSubAccount == 'true') {
FirstName.visible = true;
LastName.visible = false;
AccountTitling.visible = true;
lblFirstName.visible=false;
lblLastName.visible=false;
}
Please help as I m stuck here...
For Visible = false;
document.getElementById('FirstName').style.visibility="hidden";
For Visible = true;
document.getElementById('FirstName').style.visibility="visible";
To Enable:
document.getElementById('FirstName').disabled = false;
To Disable:
document.getElementById('FirstName').disabled = true;
Following can be done for
Non Visible
document.getElementById('id-name').style.display='none';
Visible
document.getElementById('id-name').style.display='block';
Disable
document.getElementById('id-name').setAttribute('disabled', 'disabled');
Enable
document.getElementById('id-name').removeAttribute('disabled');
No; document.getElementById will only get the element with the ID you specify (the HTML spec is quite clear that only one element on a page can have a specific ID).
Each radio button has a different ID attribute, but if you look at the HTML source of a page, you will see that all radio buttons in the list have the same NAME attribute. This is what you should use "the name of the radio button".
onclick="GetRadioButtonValue('<%= radiobuttonlist1.ClientID %>')"
function GetRadioButtonValue(id)
{
var radio = document.getElementsByName(id);
for (var j = 0; j < radio.length; j++)
{
if (radio[j].checked)
alert(radio[j].value);
}
}