473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

looping thru controls

I am new to ASP.net. All my work so far has been in VB ans Access.

I want to dynamically popluate a list box with four columns of data. Only
one column is the value. This is what I have tried so far. How can I get
all four columns visible in the list box.

cSQL = "Select CustNum, Name, Address, City from tblCust where
Substring(Phone,4,7) = '" & txtInput.Text & "'"

Dim cmdList As New
SqlClient.SqlCommand(cSQL, conn)
Dim rs As SqlClient.SqlDataReader
Dim dtblNames As New DataTable
Dim drowNew As DataRow
rs = cmdList.ExecuteReader
dtblNames.Columns.Add(New DataColumn("CustID", GetType(String)))
dtblNames.Columns.Add(New DataColumn("CustName", GetType(String)))
dblNames.Columns.Add(New ataColumn("Address", GetType(String)))
dtblNames.Columns.Add(New DataColumn("City", getType(String)))

While rs.Read()
drowNew = dtblNames.NewRow()
drowNew("CustID") = rs(0)
drowNew("CustName") = rs(1)
drowNew("Address") = rs(2)
drowNew("City") = rs(3)
dtblNames.Rows.Add(drowNew)
End While

' I want the datatextfield to be all four values in four columns.
' How can I do it?
lstNames.DataTextField = "CustName"
lstNames.DataValueField = "CustID"
lstNames.DataBind()
Nov 21 '05 #1
2 1001
Michael,

You do it a little bit to difficult for yourself, I thought that it should
work as you wrote it, however much easier is. (written in this message not
checked so watch typos)
\\\
cSQL = "Select CustNum, Name, Address, City from tblCust where
Substring(Phone,4,7) = '" & txtInput.Text & "'"
Dim cmdList As New
dim da as new SqlClinet.SqlDataadapter(sSQL, conn)
Dim dtblNames As New DataTable
lstNames.DataTextField = "CustName"
lstNames.DataValueField = "CustID"
lstNames.DataBind()
///

However with the listbox you cannot get the 4 columns, therefore they made
the datagrid or the datalist, for which you do not have to set the
datatextfield and datavaluefield.

However you have to configure that using the designer (or write a lot in
HTML)

I hope this helps?

Cor

Nov 21 '05 #2
brr..............
I deleted to much and forgot something to write
\\\
cSQL = "Select CustNum, Name, Address, City from tblCust where
Substring(Phone,4,7) = '" & txtInput.Text & "'"
Dim cmdList As New
dim da as new SqlClinet.SqlDataadapter(sSQL, conn)
Dim dtblNames As New DataTable da.fill(dtblNames)
lstNames.DataSource = dtblNames lstNames.DataTextField = "CustName"
lstNames.DataValueField = "CustID"
lstNames.DataBind()
///

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: RC | last post by:
I have a table that lists many box numbers. Each box number has a Pallet Number (indicating which pallet the box is in). When the Pallets are loaded into a shipping Container I need to update the...
4
by: Nick | last post by:
Hi - I'm trying to loop through the textboxes on a page to unlock them for editing. The Enabled property is set to false, and the following code is on an 'Edit' button on the form. Can anyone tell...
5
by: Craig G | last post by:
how do i go about this thru serverside code (VB.NET)? any links to any articles anywhere? basically i just want something simple that will loop thru all txt & cbo server side controls, and then...
6
by: Craig G | last post by:
i have the routine setup as below. the ctlCollection is populated with Page.Controls. but it only ever brings back 3 controls even though there is more than this on the page the control types it...
1
by: Jim in Arizona | last post by:
Using VB .. Is there a way to loop through all drop down lists on a web form checking for a specific value (ddlDropDown.SelectedValue) and then, based on that value, cause a specific label to go...
2
by: pob | last post by:
Whats the difference between using a control or a listbox when looping thru a listbox. In example 1 it dims a listbox and an example 2 it dims a control. Please explain. Thanks in advance ...
1
by: pds79 | last post by:
Hi everyone, I'm a newbie to the forum. I have an issue and was hoping to get some assistance/ideas: Im trying to read a XML file into two record sets. I can acheive looping through the...
1
by: tshad | last post by:
I was trying to do this in Javascript but found I can't do spans (which is what Labels turn into). I can do a loop thru a control list something like: Public Sub LoopingControls(ByVal oControl...
6
by: mahowe | last post by:
Hi, I have had this problem for a while and have not been able solve it. What im looking at doing is looping thru my patient table and trying to organise the patients in to there admission...
4
by: sparks | last post by:
well I am trying to get around looking at all the buttons with a case statement so I was trying this. Public Sub looking(ctlname) Dim ctl As OptionGroup Dim btn As ToggleButton ctl =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.