Welcome to WebmasterWorld Guest from 54.166.224.46

Forum Moderators: ocean10000

Message Too Old, No Replies

Loop asp.net assistance

     
3:25 pm on Sep 10, 2011 (gmt 0)

5+ Year Member



I have a search box and am asking users to enter a last name. What I have works, but it only returns one answer. It is very possible that there could be results where users have the same last name. Instead of displaying

FNAME, LNAME
CITY, STATE, ZIP

I want

FNAME, LNAME
CITY, STATE, ZIP

FNAME, LNAME
CITY, STATE, ZIP

FNAME, LNAME
CITY, STATE, ZIP

FNAME, LNAME
CITY, STATE, ZIP


Any suggestions?
Thanks
3:26 pm on Sep 10, 2011 (gmt 0)

5+ Year Member



If this helps, this is the code I have that displays one result.


Dim strid = txtlname.Text
'Response.write(strid)


Dim cmsData As New DataTable
Dim cmsCt As New SqlConnection(ConnectionString)
Dim cmsAdapt As New SqlDataAdapter

'Try
Dim cmsQuery As String = "SELECT * FROM tblinfo WHERE VISIBLE = '1' AND LNAME = @LNAME "




cmsAdapt.SelectCommand = New SqlCommand(cmsQuery, cmsCt)
cmsAdapt.SelectCommand.Parameters.Add(New SqlParameter("@LNAME", strid))

cmsAdapt.Fill(cmsData)
cmsCt.Close()
' Catch ex As Exception
' lblErrors.Text = "Could not connect to CMSWebData"
'Exit Sub
' End Try

If cmsData.Rows.Count > 0 Then
Dim dr As DataRow = cmsData.Rows(0)
strfname = Utils.CheckForNull_Text(dr.Item("FNAME"), "")
strlname = Utils.CheckForNull_Text(dr.Item("LNAME"), "")
strcity = Utils.CheckForNull_Text(dr.Item("CITY"), "")
strstate = Utils.CheckForNull_Text(dr.Item("STATE"), "")
strcomments = Utils.CheckForNull_Text(dr.Item("COMMENTS"), "")
strzip = Utils.CheckForNull_Text(dr.Item("ZIP"), "")
strwherefound = Utils.CheckForNull_Text(dr.Item("WHERE_FOUND_TOWN"), "")
strwherefoundstate = Utils.CheckForNull_Text(dr.Item("WHERE_FOUND_STATE"), "")
strwherefoundloc = Utils.CheckForNull_Text(dr.Item("WHERE_FOUND_LOCATION"), "")
strwherefounddate = Utils.CheckForNull_Text(dr.Item("WHERE_FOUND_DATE"), "")


'labels to display information
lblfname.Text = strfname
lbllname.Text = strlname
lblcity.Text = strcity
lblstate.Text = strstate
lblcomments.Text = strcomments
lblzip.Text = strzip
lblwherefound.Text = strwherefound

lblwherefoundstate.Text = strwherefoundstate
lblwherefoundlocation.Text = strwherefoundloc
lblwherefounddate.Text = strwherefounddate



MultiView1.SetActiveView(View2)
7:53 pm on Sep 12, 2011 (gmt 0)

5+ Year Member



Bueller? Bueller?
8:06 pm on Sep 12, 2011 (gmt 0)



Hi,

It's not so much an issue with the code as an issue with the page layout.

You've declared only one set of labels, lblfname etc so the page can physically display only one set of results.

A possible solution would be to use a data grid on the page and bind the SQL adapter to it.
11:46 pm on Sep 13, 2011 (gmt 0)

10+ Year Member



Better yet would be a Repeater, much more lightweight than a data grid.
12:16 pm on Sep 14, 2011 (gmt 0)

5+ Year Member



OK. Thank you. I will give it a shot tonight. I reused code from another project where there was only result.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month