tags:

views:

29

answers:

1

Hi I get the error 'ListViewWebPart' is a 'namespace' but is used like a 'type'

here is my code i don't know how to fix this any ideas?

namespace TestSolution
{

    [Guid("d3425822-6979-476d-a8cb-04de9521d1b4")]
    public class TestListViewWebPart : System.Web.UI.WebControls.WebParts.WebPart
    {


        public TestListViewWebPart()
        {
            this.ExportMode = WebPartExportMode.All;
        }



        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            try
            {
                SPSite site = new SPSite("http://test.local/docs");
                SPWeb web = site.OpenWeb();
                SPList list = web.Lists["ListName"];



                ViewToolBar toolbar = new ViewToolBar();

                SPContext context = SPContext.GetContext(this.Context, list.Views["SomeView"].ID, list.ID, SPContext.Current.Web);

                toolbar.RenderContext = context;

                Controls.Add(toolbar);



                // Instantiate the web part
                ListViewWebPart lvwp = new ListViewWebPart();
                lvwp.ListName = list.ID.ToString("B").ToUpper();
                lvwp.ViewGuid = list.Views["SomeView"].ID.ToString("B").ToUpper();
                //lvwp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();

                lvwp.GetDesignTimeHtml();
                this.Controls.Add(lvwp);
            }
            catch (Exception ex)
            {
                Label lbl = new Label();
                lbl.Text = "Error occured: ";
                lbl.Text += ex.Message;
                this.Controls.Add(lbl);
            }
        }


        protected override void Render(HtmlTextWriter writer)
        {
            EnsureChildControls();
            base.Render(writer);
        }
    }
}
A: 

Somewhere in your application you declared a namespace ListViewWebPart. In you code now you also declare a varible with the same name, which is not permitted. In general, you should never have a class and a namespace with the same name, this mostly will lead to problems.

If you want to avoid renaming you have to specify the complete namespace for your variable like this:

YourNamespace.ListViewWebPart lvwp = new YourNamespace.ListViewWebPart();

or even better:

global::YourNamespace.ListViewWebPart lvwp = new global::YourNamespace.ListViewWebPart();
codymanix