title: Grey Out Certain Items C#
body: <p>I would like to disable certain members of an <code>ItemList</code>. I have tried variations on the following code, but nothing seems to work. I wish to have the disabled <code>Items</code> remain in the <code>list</code>, but be grey'ed out. I have seem similar posts on this subject, but nothing seems to work.</p>
  
  <pre><code>List&lt;SelectListItem&gt; selectitem = new List&lt;SelectListItem&gt;();
  
  selectitem.Add(new SelectListItem { Text = "Select", Value = "-1", Disabled = false });
  
  while (reader.Read())
  {
  string displayText = "TextTest";
  string displayValue = "ValueTest";
  
  selectitem.Add(new SelectListItem { Text = displayText, Value = displayValue, Disabled = true });
  }
  
  EstimateDropDownList.DataSource = selectitem;
  EstimateDropDownList.DataTextField = "Text";
  EstimateDropDownList.DataValueField = "Value";
  EstimateDropDownList.DataBind();
  </code></pre>
  
  <p>...</p>
  
  <pre><code>  internal class SelectListItem
      {
          public string Text { get; set; }
          public string Value { get; set; }
          public bool Disabled { get; set; }
      }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&lt;asp:DropDownList ID="EstimateDropDownList" runat="server" Width="200px" Height="27px"
      AutoPostBack="true" OnSelectedIndexChanged="EstimateDropDownList_SelectedIndexChanged"&gt;
  &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>I also tried this, but this did not work either.</p>
  
  <pre><code>EstimateDropDownList.DataSource = selectitem;
  
  foreach (ListItem item in EstimateDropDownList.Items)
     {
       if (true)
        {
            item.Attributes.Add("disabled", "disabled");
        }
     }
  
  EstimateDropDownList.DataTextField = "Text";
  EstimateDropDownList.DataValueField = "Value";
  EstimateDropDownList.DataBind();
  </code></pre>