Hi,
I have a webdropdown with loadondemand enabled and enableautofiltering set to server. The datasource for the control is a datatable with 4000+ items.
I assign the datasource on every postback but i only do a databind when the page loads for the first time.
Load on demand works fine, but when i select an item that's further in the list, the selection is lost after a postback and jumps to the first visible item in the list. Is there a workaround for this behaviour?
I use netadvantage v2010.3
Sample code to reproduce the behaviour
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True"> </asp:ScriptManager> <ig:WebDropDown ID="WebDropDown1" runat="server" EnableLoadOnDemand="True" Width="200px" EnableAutoCompleteFirstMatch="False" EnableAutoFiltering="Server" PageSize="10"> </ig:WebDropDown> <asp:Button ID="Button1" runat="server" Text="Button" /> </form>
Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim dt As DataTable If Session("dt") Is Nothing Then dt = New DataTable("personen") dt.Columns.Add("userid", GetType(System.String)) Dim dr As DataRow Dim j As Integer = 100 For i As Integer = 1 To 4000 dr = dt.NewRow dr.Item("userid") = i dt.Rows.Add(dr) Next Else dt = CType(Session("dt"), DataTable) End If Me.WebDropDown1.DataSource = dt Me.WebDropDown1.TextField = "userid" Me.WebDropDown1.ValueField = "userid" If Not Me.IsPostBack() Then Me.WebDropDown1.DataBind() End If End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Dim test As String = Me.WebDropDown1.SelectedItem.Text End SubEnd Class
Before postback:
After postback:
Any tips?
Thanks in advance!!
Hello,
That seems to do the trick, many thanks!
I still find it very confusing that the databound event is called after a postback even when you do not call the databind() method.
What i did was the following in the form_load event
If Not Me.IsPostBack() Then Me.WebDropDown1.DataBind() End If
What exactly causes the databound event to be fired on postback?
Hello Marjin,
As Konstantin has advised , you have to restore your selected state and set this selected index after the databinding has been performed.
For example I can suggest you keeping the selected item in the session variable.
You can set it inside the Button_Click handler and restore the selected state and current value in DataBound handler
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim test As String = Me.WebDropDown1.SelectedItem.Text
Session("SelectedItem") = Me.WebDropDown1.SelectedItem
Label1.Text = test
End Sub
Protected Sub WebDropDown1_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles WebDropDown1.DataBound
If Session("SelectedItem") IsNot Nothing Then
Dim selectedItem As DropDownItem = Session("SelectedItem")
Me.WebDropDown1.SelectedItems.Add(selectedItem)
Me.WebDropDown1.CurrentValue = selectedItem.Text
End If
Let me know if you need further assistance.
Because it took a while before we got an answer on the forum we allready opened a case last week in the support section. (casenumber: CAS-65192-WKH885, under a different login though)
The case has an example project attached to demonstrate the problem.
Thanks in advance!
Hi again,
I have created a case and have requested the developer support team to assist me by creating a sample so I could further investigate the issue. Thanks a lot for your patience, I would look into this further as soon as I have the sample created.
Best regards,
Hi, thanks for the reply!
I only do a databind on the initial page load, so there is no databinding when a postpack occurs.
On each postback however i have to set the datasource again from session for loadondemand to work.