Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Asp.Net Programming

listbox in usercontrol

   I have a question about using listbox in a customized user control.I use
a listbox directly in a asp.net page and it works very well,but when I use
the same code in a user control,things get different. My code is listed
      //declare listbox in the user control ascx file:

        <asp:ListBox ID="ListBox1" runat="server" Height="344px"

        //bind the listbox in the user control's page_load event:
             string dir = @"e:\work\";

        if (!IsPostBack)
            ListBox1.DataSource = ListFiles(new DirectoryInfo(dir));

        //the codes that realize ListFile method
        public Array ListFiles(DirectoryInfo dir)
        if (!dir.Exists)
            return null;

        if (dir == null)
            return null;

        FileSystemInfo[] files = dir.GetFileSystemInfos();
        ArrayList al = new ArrayList();
        for (int i = 0; i < files.Length; i++)
            FileInfo file = files[i] as FileInfo;
            if (file != null && file.Extension == ".doc")
+ 1));
        Array a = al.ToArray();
        return a;

    phenomenon: when I put these code in my user control to use this
listbox, when the page is postbacked,the content in listbox is empty. Can
anyone help me? if I don't use "if( !ispostback) ",the content of listbox
can be seen again,but another problem is when I  select any item in the
listbox,the selected status can not be preserved after another postback
event occur.

   Thanks anyway!



Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc