Asp.Net Interview Questions Asp.Net 2.0/3.5 Sample Interview Questions and Answers. Interview Tips for a successful job Interview
The aim of this article is to answer the question 'How do I add items to a DropDownList?'
Initially as part of the declaration for the DropDownList we can also define a number of items, much in the same way as in classic ASP.
<asp:DropdownList id=ddlDropDown runat="server"> <asp:ListItem Text="Daily" Value="Daily" Selected="True"></asp:ListItem> <asp:ListItem Text="Weekly" Value="Weekly"></asp:ListItem> <asp:ListItem Text="Monthly" Value="Monthly"></asp:ListItem> </asp:DropdownList>
Now for the second part of the exercise. In our code behind we wish to be able to add more items to this list. To do this we add the following at the appropriate place in our code
ddlDropDown.Items.Add("Yearly")
However, this only allows us to add a value, we may also wist to add a value and text pair. To do this we need to do the following
ddlDropDown.Items.Add(New ListItem("1992", "(J/K)"))
Add a Delete Button to a Datagrid Add an Edit Button to a Datagrid Adding Data to a DropDownList Adding Tooltips to Datagrid Rows Authentication Binding a Datagrid to an Access Database Country Codes Datagrid Formatting the Data Datagrid Highlight a Row With Click Through Getting Current Date Time Invalid CurrentPageIndex Value Making a Datagrid Row Editable Regular Expressions Test if File Exists Using Javascript with ASP.NET Form Elements