Dynamic page title and sql datasource

Posted on 2008-06-18
Last Modified: 2010-05-18
Is it possible to change the title of page based on the query results while using a sql datasource?

Question by:JRockFL
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 21812319
Sure just use the  Page.Title property to change the title to whatever you want.

if results=1 then
Page.Title = "Title2
end if

Open in new window


Author Comment

ID: 21812355
I don't think that is going to do it.
Here is some code.

I want to display companyname in the title
                    <asp:SqlDataSource ID="sdsCompanyDetails" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectDbMilitary %>"
                        SelectCommand="SELECT [CageCode], [CompanyName], [DBA], [DivisionName], [State], [City], [AddressLine3], [AddressLine2], [AddressLine1], [SicCode], [Fax], [Phone], [Country], [ZipCode] FROM [vwCageCodes] WHERE ([CageCode] = @CageCode)">
                            <asp:QueryStringParameter Name="CageCode" QueryStringField="cage" Type="String" />

Open in new window

LVL 14

Accepted Solution

Dustin Hopkins earned 500 total points
ID: 21812517
Sure just do something like this with your pageload and another sub.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Request.QueryString("cage") Is Nothing Then
            Dim cagecode As String = Request.QueryString("cage").ToString
        End If
    End Sub
    Sub Loadtitle(ByVal _cagecode As String)
        Dim data
        Dim strSQL = "SELECT top(1) [CompanyName] FROM [vwCageCodes] WHERE ([CageCode] = " & _cagecode & ")"
        Dim sSqlConnectionString As String = ConfigurationManager.ConnectionStrings("ConnectDbMilitary").ToString
        Dim SqlConn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(sSqlConnectionString)
            'Specify the SQL string
            Dim SqlCmd As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand(strSQL, SqlConn)
            data = SqlCmd.ExecuteScalar
            Page.Title = data.ToString.Trim
        Catch ex As Exception
        End Try
    End Sub

Open in new window


Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question