Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. problems casting an object to a listbox

problems casting an object to a listbox

Scheduled Pinned Locked Moved ASP.NET
designsysadminhelp
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    foobarDividedByZero
    wrote on last edited by
    #1

    Hi, I have a series of pages to create that will each have a bunch of listboxes on them, each containing a listing of files in a directory. I'm trying to get the page down to basics where i only have to plug in the correct paths to the folders, but I'm hitting a problem casting 'object sender' to a listbox - the SelectedItem is always the first item, not what was actually selected. here is the entire code-behind (stripped down to basics): public partial class departments_safety_play : System.Web.UI.Page { private static readonly string year = DateTime.Now.Year.ToString(); private static readonly string root = @"../..//FIBRELINE/"; private readonly string pathFibrelineA = string.Format(@"{0}{1}/A-SHIFT/", root, year); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string folderToBrowse = Server.MapPath(pathFibrelineA); utilityLib.ShowFilesInWithValue(folderToBrowse, lstFibrelineA, pathFibrelineA); } } protected void lbSelectedIndexChanged(ListBox lb) { string dir = lb.SelectedValue + lb.SelectedItem.Text; string popupScript = "" + "window.open('" + dir + "', 'CustomPopUp', " + "'width=600, height=500, menubar=1, resizable=1, location=1')" + ""; ClientScript.RegisterStartupScript(GetType(), lb.SelectedItem.Text, popupScript); } protected void SelectedIndexChanged(object sender, EventArgs e) { ListBox lb = (ListBox) sender; lbSelectedIndexChanged(lb); } }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups