Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Using Label Controls with a DataList
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Using Label Controls with a DataList

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Using Label Controls with a DataList
    Posted: 11 October 2004 at 10:49pm

I have an ASP.Net web page that retrieves state abbreviations as the values from a querystring. I have a desire to display the full state name in the title of the web page. I want to be able to retrieve the datafield from the table before I create a label control to display it. I have tried several different things, but I have been unsuccessful so far. Can someone please look at my code and see how I might be able to solve this problem? I have bolded the important parts of this code.

Here's the error message that I got:

Compiler Error Message: BC30367: Class 'System.Data.SqlClient.SqlDataAdapter' cannot be indexed because it has no default property.

Source Error:

Line 61: 		
Line 62: 		'Set module level variable for page title display 
Line 63:         FullState = dtaSpa("StateName") & "" 

Here's my code:

'---------------------------------------------
' name: BindDataList()
'---------------------------------------------
Sub BindDataList()

              Dim strConnect As String
              Dim objConnect As New System.Data.SqlClient.SQLConnection(ConnectionString())
              Dim objCommand As New System.Data.SqlClient.SQLCommand
              Dim strSQL as String
              Dim dtaSpa As New System.Data.SqlClient.SQLDataAdapter()
              Dim dtsSpa As New DataSet()
              Dim strChosenState as String
    Dim FullState as String
    
              objConnect.Open()
             
      
        'Get incoming querystring values
                  strChosenState = request.params("State")
    
              'Start SQL statement
              strSQL = "Select * From Area, State"
    strSQL = strSQL & " where Area.State = State.State"
    
              strSQL = strSQL & " and Area.State = '" & strChosenState & "'"

    strSQL = strSQL & " Order By Area"

  
        Trace.Warn ("strSQL = " & strSQL)

        'Set the Command Object properties
        objCommand.Connection = objConnect
        objCommand.CommandType = CommandType.Text
        objCommand.CommandText = strSQL

        'Create a new DataAdapter object
        dtaSpa.SelectCommand = objCommand

        'Get the data from the database and
        'put it into a DataTable object named dttSpa in the DataSet object
        dtaSpa.Fill(dtsSpa, "dttSpa")

        'Set the DataSource property of the DataGrid
        dtlSpa.DataSource = dtsSpa
  
  'Set module level variable for page title display
        FullState = dtaSpa("StateName") & ""


        'Bind all the controls on the page
        dtlSpa.DataBind()
  
        'Display chosen StateName
        'lblState.Text = "Chosen Category:    " & strChosenState

        'Show chosen category in our navigation breadcrumb
        'lblChosenCategory.Text = strChosenCategory

        'Display category choice in page title
        'litTitle.Text = "Find a Spa Store For " & FullState


End Sub

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 12 October 2004 at 2:01am
Change

FullState = dtaSpa("StateName")


To:

FullState = dtsSpa.Tables(0).Rows(0).Item("StateName")
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 12 October 2004 at 1:32pm
Thank you for the code! It worked the way I wanted it to.

Edited by Misty
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.