Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Can not import this web part

$
0
0

dll is in the GAC. 

safe control is listed correctly.  Not sure why.  Code is listed below.  any help is appreciated.

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

namespace VendorDropdown.VisualWebPart1
{
    [ToolboxItemAttribute(false)]
    public class VisualWebPart1 : WebPart
    {
           // Visual Studio might automatically update this path when you change the Visual Web Part project item.
             private const string _ascxPath = @"~/_CONTROLTEMPLATES/VendorDropdown/VisualWebPart1/VisualWebPart1UserControl.ascx";
           String drpListSelected = "";
           DropDownList drpList = new DropDownList();

           protected override void CreateChildControls()
           {
               Control control = Page.LoadControl(_ascxPath);
               SPSite site = SPContext.Current.Site;
               SPWeb web = SPContext.Current.Web;

               SPList list1 = web.Lists["Vendor"];
               var listitems = list1.Fields["Company"];
               drpList.DataSource = listitems;
               drpList.DataTextField = "Company";
               drpList.DataValueField = "ID";
               drpList.DataBind();
               Controls.Add(control);

               drpList.SelectedIndexChanged += new EventHandler(this.ddlAllLists_SelectedIndexChanged);
           }

           void ddlAllLists_SelectedIndexChanged(object sender, EventArgs e)
           {
               try
               {
                   //set the selected value and logic
                   drpListSelected = drpList.SelectedValue;
                   this.Page.Response.Redirect("~/Lists/Vendor/DispFormVendor.aspx?iD="+ drpListSelected);

               }
               catch (Exception ex)
               {
                   //  LogManger.WriteLog(" Error in EventCalendarWebPart.cs ddlAllLists_SelectedIndexChanged()" + ex.ToString());
               }
           }
        protected override void Render(HtmlTextWriter output)
      {
          EnsureChildControls();
          base.RenderContents(output);
      }

    }
}


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>