Hi
I'm using a WebDropDown with an ItemTemplate that renders multiple columns from an underlying datasource, just like shown in the video from craigshoemaker. I've set the AutoPostback property to true. Everything loads well when I run the page. When I select a value the page does a postback (as desired).But now all the items from the WebDropDown are empty, however the template-layout is still applied and the Value and Text properties are still filled up.It seems that the DataItems get null, because they're not being saved in the ViewState?
Is this normal behavior? The only workaround I can find is to DataBind the control on every postback.
I've attached a sample project (VB.NET and version 9.1.20091.2040)
Hi,
Yes this is a known limitation. It is ok for controls to call DataBind() if they have a data binding reference to the DataItem. Otherwise this reference cannot be restored. The WebDataGrid has a solution for this called DataViewState (EnableDataViewState=true).
Thanks,
Angel
Hi Angel
On one hand I can understand that's not being saved in the ViewState (it would get bloated), on the other hand if you would use multiple WebDropDown-controls that binds on every postback (for instance if they were cascaded), you would also get a performance issue, not?
Anyway thanks for your help.
Kind regards
Kevin
Hi Kevin,
If you disable ViewState (EnableViewState=false), and do DataBind on every postback, I think there shouldn't be any noticeable performance hit.
Please let me know if you notice any degradation there.
I have the same issue and I have done what is suggested above but I still have empty items when I select the 2nd time. Here is the code. Why wont the webdropdown display the items the 2nd time? If I remove the ItemTemplate all is well except that the items are shown as hyperlinks which I do not want.
<ig:WebDropDown ID="webDropDownProvince0" runat="server" DisplayMode="DropDownList" Width="200px" TabIndex="4" AutoPostBack="True" ondatabound="webDropDownProvince0_DataBound" onselectionchanged="webDropDownProvince0_SelectionChanged" EnableViewState="False"> <DropDownItemBinding TextField="ProvinceName" ValueField="ProvinceName" /> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "ProvinceName")%> </ItemTemplate> </ig:WebDropDown>
Ok now it's clear to me. DataItem for controls is not kept in ViewState, only the item is - that is, the actual DropDownItem. Therefore if you do templating and bind in this way, referring to the DataItem, this is the expected behavior.
To fix this, you can call DataBind() on every postback , and it will work fine.