Is there a way to set the current display text and value of a webdropdown in the server-side(code behind vb file)?
Thanks,
Sunil Mehta.
Hello Sunil,
In order to assign the selected item for your WebDropDown from the code behind file, you must set the SelectedItemIndex property of your WebDropDown. One way to do this is to find the item from the item list using FindItemsByValue.
For example:
//For this example, I am using a simple object for demonstration. Obviously your Model would be used instead.
Public Class item
Public Property value() As Integer Get Return m_value End Get Set m_value = Value End Set End Property Private m_value As Integer Public Property text() As String Get Return m_text End Get Set m_text = Value End Set End Property Private m_text As String Public Sub New(val As Integer, txt As String) value = val text = txt End Sub End Class
//Here we bind the sample items to the list
ItemDropDown.DataSource = New BindingList(Of item)() From { _ New item(1, "item1"), _ New item(2, "item2"), _ New item(1, "item3") _ } ItemDropDown.ValueField = "value" ItemDropDown.TextField = "text" ItemDropDown.DataBind()
//Lastly we find the item and then select it by index.
Dim index = ItemDropDown.Items.FindItemByValue("2").Index
ItemDropDown.SelectedItemIndex = index
Alternatively, you can also loop through the items list in order to compare against the item text or the item text and value simultaneously.
Sincerely,JonInfragistics, Inc.<http://es.infragistics.com/support/get-help.aspx>