I was wondering if it was possible to populate the html page title using a field from my SQL Datasource? Using Master pages means that the page title is always the same but I'd like it to be relevent to the data the page is showing (which is from an SQL
Datasource also )and as such I'd like to take one of the fields from that query and populate the title tag with is. Many thanks.
Thanks for the replies so far. Here is the code I wanted to use. I am getting an error howeve:
protected void Page_Load(object sender, EventArgs e)
{
System.Data.DataView dv = null;
dv = (Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
System.Data.DataRowView dr = dv[0];
string thetitle = Convert.ToString(dr["CourseTitle"]);
Page.Header.Title = thetitle;
}
Error:
Type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?)
I'm not sure why I'm getting this message however as I am using system.data and I have ensure the reference has been added to the projects. Can anyone help?
Yanayaya
Member
35 Points
200 Posts
Title from SQL Datasource
Jan 21, 2013 09:16 AM|LINK
Hello,
I was wondering if it was possible to populate the html page title using a field from my SQL Datasource? Using Master pages means that the page title is always the same but I'd like it to be relevent to the data the page is showing (which is from an SQL Datasource also )and as such I'd like to take one of the fields from that query and populate the title tag with is. Many thanks.
DarrellNorto...
All-Star
86703 Points
9638 Posts
Moderator
MVP
Re: Title from SQL Datasource
Jan 21, 2013 09:40 AM|LINK
If your MasterPage Head control has runat=server, then you can do this in your content page's page_load:
protected void Page_Load(object sender, EventArgs e) { Page.Title = someValueFromDatabase; }Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
oned_gk
All-Star
31561 Points
6447 Posts
Re: Title from SQL Datasource
Jan 21, 2013 10:36 AM|LINK
SqlDataSource1.SelectParameters["id"].DefaultValue = 1; //sample pass param DataTable dt = ((DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty)).Table; Page.Title = dt.Rows[0][0].ToString();Yanayaya
Member
35 Points
200 Posts
Re: Title from SQL Datasource
Jan 25, 2013 01:32 PM|LINK
This looks interesting but would I not have to address the SQL Datasource first before I can decalre a field name from the table?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Title from SQL Datasource
Jan 27, 2013 01:26 AM|LINK
Yes, I think so.
Yanayaya
Member
35 Points
200 Posts
Re: Title from SQL Datasource
Jan 28, 2013 07:52 AM|LINK
I'm sruggling to get this to work could you perhaps expand on the code a bit so I can see where I'm going wrongs. Thanks :)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Title from SQL Datasource
Jan 28, 2013 08:10 AM|LINK
What codes have you done?
Yanayaya
Member
35 Points
200 Posts
Re: Title from SQL Datasource
Jan 28, 2013 09:59 AM|LINK
I was going to use the above gode but I'm unsure how to reference my sql datasource. So as it stands I still have nothing.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Title from SQL Datasource
Jan 28, 2013 10:28 AM|LINK
Please use SqlCommand to read out the specific row from table.
Yanayaya
Member
35 Points
200 Posts
Re: Title from SQL Datasource
Feb 14, 2013 11:20 AM|LINK
Hello there,
Thanks for the replies so far. Here is the code I wanted to use. I am getting an error howeve:
protected void Page_Load(object sender, EventArgs e) { System.Data.DataView dv = null; dv = (Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty); System.Data.DataRowView dr = dv[0]; string thetitle = Convert.ToString(dr["CourseTitle"]); Page.Header.Title = thetitle; }Error:
Type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?)
I'm not sure why I'm getting this message however as I am using system.data and I have ensure the reference has been added to the projects. Can anyone help?