raphael232
Programmer
Hi, i used the objectdatasource to the bind the dropdownlist control to my table adapter successfull, for example:
but i need a please select option at the top. I'm using visual studio 2005 and i selected edit items for the control and tried adding one but this did not work. My only other way was to put some code in the page load event handler:
but this seems like alot of code to do a simple job. Appreciate your feedback. Thanks
Code:
<asp:DropDownList ID="lstCategoryID" runat="server" DataSourceID="ObjectDataSource1" DataTextField="ID" DataValueField="fldCategory">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCategories" TypeName="KITTableAdapters.tbdCategoriesTableAdapter">
</asp:ObjectDataSource>
but i need a please select option at the top. I'm using visual studio 2005 and i selected edit items for the control and tried adding one but this did not work. My only other way was to put some code in the page load event handler:
Code:
Dim CategoriesAdapter As New KITTableAdapters.tbdCategoriesTableAdapter
Dim Categories As KIT.tbdCategoriesDataTable
Dim Items As New ListItemCollection
Dim Row As KIT.tbdCategoriesRow
Dim TopItem As New ListItem
TopItem.Text = "-- Please Select --"
TopItem.Value = ""
Items.Add(TopItem)
Categories = CategoriesAdapter.GetCategories()
For Each Row In Categories
Dim Item As New ListItem
Item.Text = Row.fldCategory
Item.Value = Row.ID
Items.Add(Item)
Next
lstCategoryID.DataSource = Items
lstCategoryID.DataTextField = "Text"
lstCategoryID.DataValueField = "Value"
lstCategoryID.DataBind()
but this seems like alot of code to do a simple job. Appreciate your feedback. Thanks