Print Page | Close Window

Using Label Controls with a DataList

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=12135
Printed Date: 28 March 2026 at 5:31pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Using Label Controls with a DataList
Posted By: Misty
Subject: Using Label Controls with a DataList
Date 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




Replies:
Posted By: Mart
Date Posted: 12 October 2004 at 2:01am
Change

FullState = dtaSpa("StateName")


To:

FullState = dtsSpa.Tables(0).Rows(0).Item("StateName")


Posted By: Misty
Date Posted: 12 October 2004 at 1:32pm
Thank you for the code! It worked the way I wanted it to.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net