Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically set the title of page through code behind

Status
Not open for further replies.

Gill1978

Programmer
Joined
Jun 12, 2001
Messages
277
Location
GB
Hi All,

I've got a sqldatasource bringing back the value (field name: FullName) that I need.

I've got this so far in the code behind
Code:
Protected void Page_Load (object sender, EventArgs e)
{
      Page.Header.Title =
}

How do I set the title to the value being brought back from the sqldatasource??

Any help would be much appreciated ...

Thanks

Julie
 
Hi ...

I've tried to use a label from the form ... i'm getting the following error :

Use the "new" keyword to create an object instance

This is the code I have so far :

Code:
this.FindControl("FormView2").Databind();
Page.Header.Title = this.FindControl("FormView2").FindControl("Employee").ToString();

Can anyone see where i'm goin wrong?

Thanks

Julie
 
- I've got a sqldatasource bringing back the value
> How? SP or execureScalar ?

- this.FindControl("FormView2").Databind();
> I think that you must first cast it to a FormView and them call the .DataBind(), like (hope i'm right) :

FormView fv;
fv = (FormView)this.FindControl("FormView2");
fv.DataBind();
Page.Header.Title = ((???)fv.FindControl("Employee")).ToString()

> What control is the "Employee"? Fill the ???
 
Hiya ..

SqlDatasource is as follows:

Code:
    <asp:SqlDataSource ID="SqlDataSourceEmployeeDetails" runat="server" ConflictDetection="CompareAllValues"
        ConnectionString="<%$ ConnectionStrings:comsys %>" 
        OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT *, (FirstName + ' ' + LastName) AS EmployeeFullName FROM [EmployeeDetails] WHERE ([EmployeeID] = @EmployeeID)">
        <SelectParameters>
            <asp:ProfileParameter Name="EmployeeID" PropertyName="EmployeeID" Type="Int32" />
        </SelectParameters>        
    </asp:SqlDataSource>

How do you cast as a FormView??

Employee is label contol (though i'll change it to a hidden field when I get the title to work) ...

Thanks for the help!!

Julie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top