Solved

Dynamic page title and sql datasource

Posted on 2008-06-18
3
383 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
  • 2
3 Comments
 
LVL 14

Expert Comment

by:Dustin Hopkins
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now