0

I have created a custom solution and used listviewwebpart to display the data. It works fine if I have only one webpart added on a page but as soon as I add another webpart the webpart start showing "Loading..." and stuck there.Below is my code for the same. I am taking weburl, list name and view name as an input from the user.

ListViewWebPart lvwp = new ListViewWebPart();
lvwp.ID = this.ID;
lvwp.Visible = true;
lvwp.EnableViewState = true;

SPList list = web.Lists[ListName.ToString()];                                

lvwp.ListName = list.ID.ToString("B").Trim().ToUpperInvariant();
lvwp.WebId = list.ParentWeb.ID;
lvwp.ListId = list.ID;

if (!string.IsNullOrEmpty(ViewName))
{
SPView defaultView = list.Views[ViewName];
lvwp.ViewId = Int32.Parse(defaultView.BaseViewID);
lvwp.ViewGuid = defaultView.ID.ToString("B").Trim().ToUpperInvariant();
}

lvwp.ChromeState = System.Web.UI.WebControls.WebParts.PartChromeState.Normal;
lvwp.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;
lvwp.HelpMode = WebPartHelpMode.Modeless;

this.Controls.Add(lvwp);

Do anyone have any idea why is it happening. Any help is highly appreciated.

Thanks

1 Answer 1

0

Since you added lvwp.EnableViewState = true; so you will need to rebind data back to list on post back.

lvwp.DataSource = SomeData;
lvwp.DataBind();
1
  • I have tried this but didn't work. First time when I browse the page then the webpart shows the data but from 2nd time onwards it doesn't. :(
    – Ankit
    Commented Jan 8, 2014 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.