0
votes

I'm creating a mini cms for my site. I want to create a page admin that let's users create pages and add meta tags to them page. So I've created a SQL Server database table with these columns:

   [PageName](primary key)
  ,[Body] - used to pull the html of the page from the sql database
  ,[Title]
  ,[Description] - meta description
  ,[Keywords] - meta keywords

I created query string using the pagename column. So far I can get the body to show but none one of the meta information. This is what I've got so far:

<asp:Repeater runat="server" ID="Repeater1" DataSourceID="BodyContent">
    <ItemTemplate>
        <asp:Label ID="lblPage" runat="server" Text='<%# Eval("Body") %>' />
    </ItemTemplate>
</asp:Repeater>

So for example my query string would be /c.aspx?pagename=test - this pulls the body content through correctly but nothing else.

SqlDataSource:

<asp:SqlDataSource ID="BodyContent" runat="server" 
     ConnectionString="<%$ ConnectionStrings:testDb %>" 
     SelectCommand="SELECT [PageName], [Body], [Title], [Description], [Keywords] FROM [PageAdmin] WHERE ([PageName] = @PageName)">
    <SelectParameters>
        <asp:QueryStringParameter Name="PageName" QueryStringField="PageName" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

How do I do the same to pull the title, keywords and description from the database?

Thanks

2

2 Answers

0
votes

They will already be contained within the SqlDataSource by virtue of the query performed;

SELECT [PageName], [Body], [Title], [Description], [Keywords]

You can then reference them in the same manner;

  <ItemTemplate>
        <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>' />
  </ItemTemplate>
0
votes

You can add meta tags in code file

Page.Title = "Your Page title";
//Page description
HtmlMeta pagedesc = new HtmlMeta();
pagedesc.Name = "Description";
pagedesc.Content = textbox2.Text;

Header.Controls.Add(pagedesc);
//page keywords
HtmlMeta pagekeywords = new HtmlMeta();
pagekeywords.Name = "keywords";

pagekeywords.Content = textbox1.Text;
Header.Controls.Add(pagekeywords);

use textbox in your cms to add meta keywords,and another for description of meta tag. separate each meta keyword by comma.