开发者

asp.net 3.5 Treeview Empty after Postback

开发者 https://www.devze.com 2023-02-09 00:53 出处:网络
I have an asp.net page which has a web control. This web control displays a Treeview, TextBox and a button.

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

精彩评论

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

关注公众号