Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Web Form Listbox population
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00761158
Message ID:
00761712
Vues:
27
Thanks Cathi. I guess that it's better to make it work then to fuss with the wizards!



>Stephen,
>
>The code I supplied would be placed in the Page_Load (code-behind) method. My preference is to write the information in code instead of using the wizards, to have better control of how the code is run.
>
>>I am following along with your sample. I am in the .NET IDE and when I click on the Web Designer Generated code I see most of what you supplied. I guess the point I'm missing is in the IDE, are you setting these commands from the "avaliable GUI assisted options", or do I go to the code behind and crank in this code to get the job done? Am I making a mistake with the IDE thinking that you can do most of it there?
>>
>>__Stephen
>>
>>>You can use a DataReader to fetch the records and populate the listbox. You want to only fetch the records the first time the page is rendered since the data won't change. Here is some sample code:
>>>
>>>
>>>//Only run the code if this is the first time the page is rendered
>>>if (Page.IsPostBack == false)
>>>{
>>>   SqlConnection  cnn = new SqlConnection(connStr);
>>>   string  strSQL = "SELECT * FROM Authors";
>>>   SqlCommand  cmd = new SqlCommand(strSQL, cnn);
>>>   SqlDataReader dr;
>>>
>>>   cnn.Open();
>>>   dr = cmd.ExecuteReader(	CommandBehavior.CloseConnection);
>>>
>>>   while ( dr.Read() )
>>>   {
>>>	lstDemo.Items.Add(string .Format("{0}: {1}, {2}",dr("Au_Id"), dr("Au_lname"), dr("Au_fname")));
>>>   }
>>>
>>>   dr.Close();
>>>}
>>>
>>>
>>>>I have a a page where the listbox is a Select distinct row from a table used in a SQLServer Data connection.
>>>>
>>>>How do I get the thing populated on load of the form? Should I create a special reader?
>>>>
>>>>TIA
>>>>
>>>>__Stephen
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform