Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Web Form Listbox population
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00761158
Message ID:
00761565
Views:
24
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform