SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 31st, 2002, 11:52 AM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
Dynamic List Box

<i><b>Originally posted by : Lee (lee.liddell@hq.hqusareur.army.mil)</b></i><br /><br />Hello, I am trying to use a function or a sub procedure to generate a list box. <br />This one code will be used to create multiple list boxes. <br />The problem is I cannot pass out the arraylist() from a function or cannot assign it to a control in a function. <br /><br />How do I pass in the control name and assign the arraylist to that control????<br /><br />Thanks,<br />~Lee<br /><br /><%@ Page Language="vb" %><br /><%@ import Namespace="System.Data" %><br /><%@ import Namespace="System.Data.sqlclient" %><br /><script runat="server"><br /> <br />Public Sub CreateMySqlDataReader(mySelectQuery As String, _<br /> myConnectionString As String, myControl as DropDownList?????????)<br /> <br /> Dim myConnection As New SqlConnection(myConnectionString)<br /> Dim myCommand As New SqlCommand(mySelectQuery, myConnection)<br /> myCommand.Connection.Open()<br /> Dim myReader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)<br /> Dim myList As New ArrayList()<br /> While myReader.Read()<br /> myList.Add(myReader.GetString(0))<br /> End While<br /><br /> '!!!!!!These are the lines I want to change depending on what control name I pass<br /> myControl.DataSource = myList<br /> myControl.DataBind()<br /> <br /> myReader.Close()<br /> myConnection.Close()<br /> End Sub<br /> <br /> <br /> sub Page_Load(Source as Object, E as EventArgs)<br /> Dim strConn as string<br /> strConn ="server=server;uid=test;pwd=test"<br /> <br /> If Not IsPostBack Then<br /> Dim SQL as String<br /> SQL = "SELECT Room_number FROM ROOM"<br /> CreateMySqlDataReader(SQL, strConn, "DropDownList1")<br /> SQL = "SELECT POC FROM POC"<br /> CreateMySqlDataReader(SQL, strConn, "DropDownList2")<br /> End If<br /> <br /> end sub <br /></script><br /><html><br /><head><br /> <title>Room Scheduler</title><br /></head><br /><body><br /> <p><br /> Room Scheduler <br /> </p><br /> <form id="NameForm" runat="server"><br /> <p>Room Number: <br /> <aspropDownList id="DropDownList1" runat="server"></aspropDownList></p><br /> <aspropDownList id="DropDownList2" runat="server"></aspropDownList></p><br /> <p><input type="submit" value="Submit" /><br /> <input type="reset" value="Clear" /></p><br /> </form><br /></body><br /></html>

Reply With Quote
  #2  
Old August 5th, 2002, 04:27 PM
Steve Schofield Steve Schofield is offline
Contributing User
ASP Free God 20th Plane (14500 - 14999 posts)
 
Join Date: Dec 2002
Posts: 14,575 Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level)Steve Schofield User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 22
<i><b>Originally posted by : Lisa (ldwelch@dcr.net)</b></i><br />Make sure that you import:<br />System.Web.UI.WebControls<br />and you should be able to declare the argument without any problems.<br /><br />Also - you may assign a sqldatareader directly to the DropDownLists datasource - without going through and creating the arraylist.<br /><br />ie.<br /> myControl.DataSource = myReader<br /> myControl.DataTextField = DisplayField<br /> myControl.DataValueField = sValueField<br /> myControl.DataBind()<br /><br />Note - The bind even autoCloses the reader for you.<br /><br /><br /><br /><br />------------<br />Lee at 7/31/2002 9:52:57 AM<br /><br /><br />Hello, I am trying to use a function or a sub procedure to generate a list box. <br />This one code will be used to create multiple list boxes. <br />The problem is I cannot pass out the arraylist() from a function or cannot assign it to a control in a function. <br /><br />How do I pass in the control name and assign the arraylist to that control????<br /><br />Thanks,<br />~Lee<br /><br /><%@ Page Language="vb" %><br /><%@ import Namespace="System.Data" %><br /><%@ import Namespace="System.Data.sqlclient" %><br /><script runat="server"><br /> <br />Public Sub CreateMySqlDataReader(mySelectQuery As String, _<br /> myConnectionString As String, myControl as DropDownList?????????)<br /> <br /> Dim myConnection As New SqlConnection(myConnectionString)<br /> Dim myCommand As New SqlCommand(mySelectQuery, myConnection)<br /> myCommand.Connection.Open()<br /> Dim myReader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)<br /> Dim myList As New ArrayList()<br /> While myReader.Read()<br /> myList.Add(myReader.GetString(0))<br /> End While<br /><br /> '!!!!!!These are the lines I want to change depending on what control name I pass<br /> myControl.DataSource = myList<br /> myControl.DataBind()<br /> <br /> myReader.Close()<br /> myConnection.Close()<br /> End Sub<br /> <br /> <br /> sub Page_Load(Source as Object, E as EventArgs)<br /> Dim strConn as string<br /> strConn ="server=server;uid=test;pwd=test"<br /> <br /> If Not IsPostBack Then<br /> Dim SQL as String<br /> SQL = "SELECT Room_number FROM ROOM"<br /> CreateMySqlDataReader(SQL, strConn, "DropDownList1")<br /> SQL = "SELECT POC FROM POC"<br /> CreateMySqlDataReader(SQL, strConn, "DropDownList2")<br /> End If<br /> <br /> end sub <br /></script><br /><html><br /><head><br /> <title>Room Scheduler</title><br /></head><br /><body><br /> <p><br /> Room Scheduler <br /> </p><br /> <form id="NameForm" runat="server"><br /> <p>Room Number: <br /> <aspropDownList id="DropDownList1" runat="server"></aspropDownList></p><br /> <aspropDownList id="DropDownList2" runat="server"></aspropDownList></p><br /> <p><input type="submit" value="Submit" /><br /> <input type="reset" value="Clear" /></p><br /> </form><br /></body><br /></html>

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Dynamic List Box


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT