Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic page title and sql datasource

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

0
Comment
Question by:JRockFL
[X]
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
3 Comments
 
LVL 14

Expert Comment

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

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

Open in new window

0
 
LVL 8

Author Comment

by:JRockFL
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)">
                        <SelectParameters>
                            <asp:QueryStringParameter Name="CageCode" QueryStringField="cage" Type="String" />
                        </SelectParameters>

Open in new window

0
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 2000 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
            Loadtitle(cagecode)
        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)
        Try
            SqlConn.Open()
            '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
        Finally
            SqlConn.Close()
            SqlConn.Dispose()
        End Try
    End Sub

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

609 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