I am facing an issue selecting first item from the webdropdown after the page loads. If I select any other items then I am able to select the first item. Please see below code
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> <script type="text/javascript"> function getItems(id) { var wdd = $find(id); if (wdd.get_items().get_length() == 0) { wdd.loadItems(); } } function onFocus() { getItems("<%= wddFocus.ClientID %>"); } function test() { getItems("<%= wddFocus.ClientID %>"); } </script></asp:Content><asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2> Welcome to ASP.NET! </h2> <p> To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>. </p> <p> You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409" title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>. </p> <div> <ig:WebDropDown ID="wddFocus" runat="server" onitemsrequested="wddFocus_ItemsRequested" Width="200px" TextField="FirstName" ValueField="Id"> <ClientEvents Focus="onFocus" /> <DropDownItemBinding TextField="FirstName" ValueField="Id" /> </ig:WebDropDown> </div> </asp:Content>
from .cs file:-
public partial class _Default : System.Web.UI.Page{ private IList<Person> _people = new List<Person>(); protected void Page_Load(object sender, EventArgs e) { _people.Add(new Person { FirstName = "Craig" }); _people.Add(new Person { FirstName = "Scott" }); _people.Add(new Person { FirstName = "Kevin" }); _people.Add(new Person { FirstName = "Jack" }); } protected void wddFocus_ItemsRequested(object sender, DropDownItemsRequestedEventArgs e) { this.wddFocus.DataSource = this._people; this.wddFocus.DataBind(); }}
What I am doing wrong here.
I figured out this issue. By setting AutoPostbackflag to true made this to work