开发者

asp.net 3.5 Treeview Empty after Postback

I have an asp.net page which has a web control. This web control displays a Treeview, TextBox and a button.

For the treeview i do on Page_Load:

if (!Page.IsPostBack) {
    BindTreeView();
}

This is my TreeView definition:

   <asp:TreeView ID="TvwData" runat="server" 
        BackColor="White" ShowCheckBoxes="Leaf" Width="99%" 
        ExpandDepth="3"  AutoGenerateDataBindings="false" 
        onselectednodechanged="TvwData_SelectedNodeChanged" 
        EnableViewState="true"
       >

The TreeView is shown correctly.

However, when I click the submit button, the following happens:

  1. Page reloads, textbox still displays my text which is OK.
  2. My Treeview doesn't display any data at all.
  3. When debugging, TvwData.CheckedNodes doesn't contain any data while I'm sure there are treeview items checked.

I really tried my best to found a solu开发者_如何学Gotion on major ASP.NET forums, but I'm clueless at this moment.

Thanks in advance!


Try the following:

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        BindTreeView();        
    }

Furthermore, remove BindTreeView(); from Page_Load.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜