How to make Blog Titles as Hyperlinks ?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 13 años
I want to display list of blog titles and make each link as hyperlink
but i just noticed that i cannot access the blogs like this:

http://localhost:1965/nopcommercestore/blog.aspx?blogpostid=7

as this blog is using url-rewriting by which i cannot access each blog by it's blogpostID

Is there any other way to accomplish what i am trying to do.. ?
Hace 13 años
ok i found the way to access the blog on the bases of id

like this: http://localhost:1965/nopcommercestore/blogpost.aspx?blogpostid=7

but now i am having problem in making it as hyperlink

i am using this:

<asp:HyperLink ID="HyperLink1" runat="server"
                        NavigateUrl='<%# string.Format("~/BlogPost.aspx?blogpostid={0}", Eval("blogpostid")) %>'
                        Text='<%# Eval("BlogPostTitle") %>'></asp:HyperLink>




----------------GETTING THIS ERROR:-------
Server Error in '/NopCommerceStore' Application.
--------------------------------------------------------------------------------

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'blogpostid'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'blogpostid'.

Source Error:


Line 48:             <asp:TemplateField HeaderText="Popular Blog Posts">
Line 49:                 <ItemTemplate>
Line 50:                     <asp:HyperLink ID="HyperLink1" runat="server"
Line 51:                         NavigateUrl='<%# string.Format("~/BlogPost.aspx?blogpostid={0}", Eval("blogpostid")) %>'
Line 52:                         Text='<%# Eval("BlogPostTitle") %>'></asp:HyperLink>
Hace 13 años
anyone ?????
Hace 13 años
Well, based on the error message you get there is no blogpostid in the object that you have connected to your control, it could also be as simple as that it's case sensitive (not sure if it is) but try with BlogPostId instead.

BR
Joakim
Hace 13 años
i don't think SQL Statements are case-sensitive but still i tried and i am getting the same error:

Server Error in '/NopCommerceStore' Application.
--------------------------------------------------------------------------------

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'BlogPostID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'BlogPostID'.

Source Error:


Line 29:             <asp:TemplateField HeaderText="Popular Blog Posts">
Line 30:                 <ItemTemplate>
Line 31:                     <asp:HyperLink ID="HyperLink1" runat="server"
Line 32:                         NavigateUrl='<%# string.Format("~/BlogPost.aspx?BlogPostID={0}", Eval("BlogPostID")) %>'
Line 33:                         Text='<%# Eval("BlogPostTitle") %>'></asp:HyperLink>

------
This is the SQL Statement that i am using:

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
            ConnectionString="Data Source=.\SQLEXPRESS;Initial Catalog=nop17;Integrated Security=True"
            ProviderName="System.Data.SqlClient"
            
            
            SelectCommand="SELECT BlogPostTitle FROM (SELECT DISTINCT TOP (5) COUNT(Nop_BlogComment.BlogCommentID) OVER(PARTITION BY Nop_BlogPost.BlogPostID) AS cnt, Nop_BlogPost.BlogPostTitle FROM Nop_BlogComment INNER JOIN Nop_BlogPost ON Nop_BlogComment.BlogPostID = Nop_BlogPost.BlogPostID ORDER BY cnt DESC ) Results"></asp:SqlDataSource>
Hace 13 años
But you don't include BlogPostID in your query...

Change the beginning of your query to:
SelectCommand="SELECT BlogPostTitle, BlogPostID FROM...

BR
Joakim
Hace 13 años
jockesoft wrote:
But you don't include BlogPostID in your query...

Change the beginning of your query to:
SelectCommand="SELECT BlogPostTitle, BlogPostID FROM...

BR
Joakim


yes i know i haven't includes BlogPost ID, that's why i posted my SQL statement here:

I have tried this:

SelectCommand="SELECT BlogPostTitle, BlogPostID FROM (SELECT DISTINCT TOP (5) COUNT(Nop_BlogComment.BlogCommentID) OVER(PARTITION BY Nop_BlogPost.BlogPostID) AS cnt, Nop_BlogPost.BlogPostTitle FROM Nop_BlogComment INNER JOIN Nop_BlogPost ON Nop_BlogComment.BlogPostID = Nop_BlogPost.BlogPostID ORDER BY cnt DESC ) Results

Then i get this error message:

Server Error in '/NopCommerceStore' Application.
--------------------------------------------------------------------------------

Invalid column name 'BlogPostID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'BlogPostID'.
Hace 13 años
Good News !!!

This command worked:

SELECT BlogPostTitle, BlogPostID FROM (SELECT DISTINCT TOP (5) Nop_BlogPost.BlogPostID, COUNT(Nop_BlogComment.BlogCommentID) OVER(PARTITION BY Nop_BlogPost.BlogPostID) AS cnt, Nop_BlogPost.BlogPostTitle FROM Nop_BlogComment INNER JOIN Nop_BlogPost ON Nop_BlogComment.BlogPostID = Nop_BlogPost.BlogPostID ORDER BY cnt DESC ) Results
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.