0

I use this code to have only the word "quatre" in my listbox of my Web Part but it's not working. Can someone explain why and give me a solution for this problem?

using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.Windows;

namespace SharePointProject2.accueil
{
    [ToolboxItemAttribute(false)]
    public partial class accueil : WebPart
    {
        public accueil()
        {
            ListBox1 = new System.Web.UI.WebControls.ListBox();
            ListBox1.Items.Add("quatre");
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();
            ListBox1 = new System.Web.UI.WebControls.ListBox();
            ListBox1.Items.Add("quatre");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            ListBox1 = new System.Web.UI.WebControls.ListBox();
            ListBox1.Items.Add("quatre");
        }
    }
}
0

Why do you do this

ListBox1 = new System.Web.UI.WebControls.ListBox();

You obviously already have the Listbox added in your .ascx. No need to create a new object. Just remove these lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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