Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown excluding items from Dropdownlist 1

Status
Not open for further replies.

yimpinay

Programmer
Nov 20, 2003
3
US
Hi, I am new to asp.net and need help on this control:
<TR>
<TD>
<asp:DropDownList id="oDropOutputType" runat="server" Width="182px">
<asp:ListItem Value="WebReport">Web Report</asp:ListItem>
<asp:ListItem Value="PrintFriendly">Print Friendly Report</asp:ListItem>
<asp:ListItem Value="ExcelSpreadsheet">Excel Spreadsheet</asp:ListItem>
</asp:DropDownList></TD>
</TR>

How do I exclude Excel Spreadsheets from the dropdown list.

Please help.

Thanks.
 
Don't understand your question. If you are hard coding the values in the markup,then just remove it, if you are binding to the control, just exclude that value.
 
I find that for any data that needs to be manipulated, not matter how simple, it's better to define the data in code, modify it, and then push to the markup.

in this case something like
Code:
var items = new List<ListItem>
   {
       new ListItem{Text = "Web Report" Value = "WebReport"},
       new ListItem{Text = "Friendly Report" Value = "PrintFriendly"},
       new ListItem{Text = "ExcelSpreadsheet" Value = "Excel Spreadsheet"},
   };
ModifyItems(items);
oDropOutputType.DataSource = items;
oDropOutputType.DataBind();
Code:
private void ModifyItems(List<ListItem> items)
{
  if(a condition is met)
  {
       items.Remove(the item);
  }
}
modifying the markup after it's already bound becomes a maintenance nightmare.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top