Create a dropdown list in Sharepoint containing List Documents with links to them
Asked Answered
P

2

0

I am looking to create a dropdown list on my default.aspx page which i want it to contain List documents/pages and when the document/page is selected the page should redirect to the selected document/page.

Any suggestions of how this can be done please?

any examples/samples would be grealy appreciated?

Thank you :)

Palaestra answered 20/10, 2009 at 16:43 Comment(1)
@sharepointer110, JonH already did hard part to you; you just need to translate it to C#ishCordeelia
P
0

Below is the solution to the question i had asked if anyone else wishes to use it

public partial class DropDown : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        FillDropDown(drpList);


    }



    void FillDropDown(DropDownList drpList)
    {

        // Use using to make sure resources are released properly   
        using (SPSite site = new SPSite("http://Site/"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList oList = web.Lists["ListName"];
                string url = string.Empty;
                foreach (SPListItem oItem in oList.Items)
                {

                    url = site.MakeFullUrl(oItem.Url);
                   // drpList.Items.Add(new ListItem(oItem.Name, url));
                    drpList.Items.Add( new ListItem(oItem.DisplayName, url));

                }

            }
        }
    }

   void Selection_Change(Object sender, EventArgs e)
      {

          Response.Redirect(this.drpList.SelectedValue);
      }

Thanks everyone for your help

Palaestra answered 21/10, 2009 at 16:20 Comment(0)
M
2

AA drop down has a selectedvalue and a selected text property. It will display the selected text.

Store the name or some sort of string that identifies the document as the SelectedText property. Store the actual hyperlink of where this document resides or where the link should take you in the SelectedValue. Set AutoPostback to true on the drop down.

In the OnSelectedIndexChanged event throw this code in:

Response.Redirect(Me.ddlLinks.SelectedValue)

Mccune answered 20/10, 2009 at 17:4 Comment(0)
P
0

Below is the solution to the question i had asked if anyone else wishes to use it

public partial class DropDown : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        FillDropDown(drpList);


    }



    void FillDropDown(DropDownList drpList)
    {

        // Use using to make sure resources are released properly   
        using (SPSite site = new SPSite("http://Site/"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList oList = web.Lists["ListName"];
                string url = string.Empty;
                foreach (SPListItem oItem in oList.Items)
                {

                    url = site.MakeFullUrl(oItem.Url);
                   // drpList.Items.Add(new ListItem(oItem.Name, url));
                    drpList.Items.Add( new ListItem(oItem.DisplayName, url));

                }

            }
        }
    }

   void Selection_Change(Object sender, EventArgs e)
      {

          Response.Redirect(this.drpList.SelectedValue);
      }

Thanks everyone for your help

Palaestra answered 21/10, 2009 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.