new to .net have a few questions concerning DataBinding to listbox

Last post 08-29-2008 4:11 PM by Zonia. 2 replies.

Sort Posts:

  • new to .net have a few questions concerning DataBinding to listbox

    08-29-2008, 9:38 AM
    • Member
      25 point Member
    • Zonia
    • Member since 08-29-2008, 8:51 AM
    • Posts 35

    Hi I am new to .net have a few questions  from a (visual 6 type, c++ directx prepective) to a (2008 express edition C#, .net prepective)

    My list box is not doing what I thought it would do,  I wanted a list box that would give me a list of all my files uploaded in a session, however It only gives me the very last file I uploaded and not all of the files in this session  when post back happens. I would like to know what the functions are doing, since what I thought the functions would do did not occour, therefore I most have missed a step; likewise, I would like to know what that step does at least that way I may better understand the .net functions,

                                                                        ps, does anyone know of a book or website that has a perpective of (visual 6 type, c++ directx) to a perpective to a  (2008 express edition C#, .net perpective), I understand COM by using directx for so long in c++, but it seems most webstes and books do not teach from that perpective. Any way here is my code, I should be back on this site at 12'o clock after I deal with some clients if in case any one has some questions about the code posted, becuase I sure do. 

     

    protected void Page_Load(object sender, System.EventArgs e)

    {

    string UpPath;

    UpPath = "C:\\UploadedUserFiles";

    if (!Directory.Exists(UpPath))

    {

    Directory.CreateDirectory("C:\\UploadedUserFiles\\");

    }

     

    }

     

     

    protected void Upload_Click(object sender, EventArgs e)

    {

    if (!File_Upload.HasFile)

    return;

    string strFileName;

    strFileName = File_Upload.PostedFile.FileName;

    string c = System.IO.Path.GetFileName(strFileName);

     

    try

    {

    File_Upload.PostedFile.SaveAs(
    "C:\\UploadedUserFiles\\" + c);

    }

    catch (Exception Handle_error)

    {

    // Not sure what I what to do here, but the try works anyway

    }

    ArrayList filesArray;

    // this session object ["List_Uploads"] is declared in Global.asax as a null in Session_Start

    if (Session["List_Uploads"] == null)

    {

    filesArray =
    new ArrayList();

    }

    else

    {

    filesArray = (
    ArrayList)Session["List_Uploads"];

    }

    filesArray.Add(File_Upload.FileName);

    ShowUpLoads_List.DataSource = filesArray;

    ShowUpLoads_List.DataBind();

    }

  • Re: new to .net have a few questions concerning DataBinding to listbox

    08-29-2008, 10:00 AM
    Answer
    • All-Star
      90,473 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,384
    • Moderator
      TrustedFriends-MVPs

    What you have looks correct.  The one thing that I find suspicious is this line:

      // this session object ["List_Uploads"] is declared in Global.asax as a null in Session_Start

    You shouldn't need to do that.  If somehow the session object "List_Uploads" is getting reset to null, it would cause the exact symptom you described.

    Steve Wellens

    My blog
  • Re: new to .net have a few questions concerning DataBinding to listbox

    08-29-2008, 4:11 PM
    • Member
      25 point Member
    • Zonia
    • Member since 08-29-2008, 8:51 AM
    • Posts 35
    Is it safe to define a session string without null, matter fact I don't think I did define it? yet it works, huh? You just throw something in and it works, cool. Any way in Page_Load, I added  ->

    if (!IsPostBack) Session["List_Uploads"] = null;

    and removed the line of code in global.asax -> function -> start session, the line being  -> session[List_Uploads] = null;

    I also tryed it without if(!isPostBack) Session["List_Uploads"]= null;

    yet I have the same problem, I only got one item, which is the last item I put in.

     If you put a String in Session such as [List_Uploads"] it starts as null without seting at null, is that ture? What about memory leaks? such as the if statement ->

    Zonia:
    if (Session["List_Uploads"] == null)

    {

    filesArray =
    new ArrayList();

    }

    else

    {

    filesArray = (
    ArrayList)Session["List_Uploads"];

    }

    wait a minute is that my problem? is the -> new arrayList() <- adding to or erasing my data. No I tested I don't think it is.

    Is ArrayList class data type what I should be using here, I am new this .net type class system.  Any ideas on whats going wrong, I guess I can try something else other than  ArrayList, is there something easier than ArrayList that would work better here?

     

     

Page 1 of 1 (3 items)
Microsoft Communities