locked
Displaying Specific Rows from Database Using a Datalist RRS feed

  • Question

  • User-2122576196 posted

    Hey guys,

    I'm using a datalist to pull data from a database. I'd like to pull only specific rows based on certain keywords. Here is a link to my site where you can find what I'm talking about ...

    http://www.darvinkmanwah.com

    Problem 1

    Under each artwork I've grouped the posts based on Tags and Software. How do I pull the rows in the databse based on those keywords under each artwork.

    Thanks ...

    Sunday, March 18, 2012 9:35 PM

Answers

  • User1829879277 posted

    First of all you need to pull the Artwork details such as Title, Tags and Software.

    Then, loop through the list of Artworks fetched from the Database. In this loop, for each Artwork, based on the Tags and Software of the Artwork, fetch posts from the Database.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 19, 2012 2:40 AM

All replies

  • User1829879277 posted

    First of all you need to pull the Artwork details such as Title, Tags and Software.

    Then, loop through the list of Artworks fetched from the Database. In this loop, for each Artwork, based on the Tags and Software of the Artwork, fetch posts from the Database.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 19, 2012 2:40 AM
  • User-2122576196 posted

    Hey Sumit,

    Thanks for the feedback. I've managed to pull the Artwork details such as Title, Tags and Software of the Artwork on the page but I don't know how to only fetch the Tags and Software of the Artwork from the database.

    Can you elaborate a bit more ... Thanks alot ...

    Monday, March 19, 2012 3:14 AM
  • User1829879277 posted

    I belive you are familiar with the SQL query and the programming language.

    In the loop of the Artworks, for each Artwork get it Tags and Software names. Using this Tags and Software names, fetch the posts.

    For more details with queries, kindly post the Table structure with some sample records.

    Monday, March 19, 2012 3:36 AM
  • User-2122576196 posted

    Hey Sumit,

    I managed to figure it out based on what you said. I went back to the query statement and instead of adding the query in the 'filter' I added it in the 'or' which allowed for multiple queries on a single page. Here's what the new 'SelectCommand' and 'SelectParameter' looks like:

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/content.mdb"
            SelectCommand="SELECT [New], [ID], [Subject], [Timestamp], [Article-Date], [Author], [ArticleContent], [ImageRights], [Approved], [Intro-Image], [Synopsis],
            [3D-Artwork], [Animated-Short-Film], [Columbus-Communications-Trinidad-Limited], [Digital-Art], [Graphic-Art], [Matrix-Designs-Limited], 
            [Matte-Painting], [Print], [Work-in-Progress], [Zbrush-Sculpt], 
            [Adobe-After-Effects], [Adobe-Photoshop], [Autodesk-Maya], [E-on-Software-Vue-xStream], [The-Foundry-Nuke]
            FROM artwork WHERE ([3D-Artwork] = ?) OR ([Animated-Short-Film] = ?) OR ([Columbus-Communications-Trinidad-Limited] = ?)  OR ([Digital-Art] = ?)  OR ([Graphic-Art] = ?) OR ([Matrix-Designs-Limited] = ?)
            OR ([Matte-Painting] = ?) OR ([Print] = ?) OR ([Work-in-Progress] = ?) OR ([Zbrush-Sculpt] = ?) OR ([Adobe-After-Effects] = ?) OR ([Adobe-Photoshop] = ?) OR ([Autodesk-Maya] = ?) 
            OR ([E-on-Software-Vue-xStream] = ?) OR ([The-Foundry-Nuke] = ?)
            ORDER BY [Article-Date] DESC">
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="" Name="3D-Artwork" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Animated-Short-Film" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Columbus-Communications-Trinidad-Limited" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Digital-Art" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Graphic-Art" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Matrix-Designs-Limited" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Matte-Painting" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Print" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Work-in-Progress" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Zbrush-Sculpt" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Adobe-After-Effects" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Adobe-Photoshop" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="Autodesk-Maya" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="E-on-Software-Vue-xStream" QueryStringField="ID" Type="String" />
                <asp:QueryStringParameter DefaultValue="" Name="The-Foundry-Nuke" QueryStringField="ID" Type="String" />
            </SelectParameters>
        </asp:AccessDataSource>

    You can check out the code here on the front page as it's working now: http://www.darvinkmanwah.com

    Problem 2

    Now that the query works, the sitemap node for that page does not give a title based on the query but only a title based on the page it is on. The page has a title but it is not dependant on the query even after I copy and paste the URL into the web.sitemap. How would I title the page based on the query?

    Loving the feedback ... Thanks ...

    Tuesday, March 20, 2012 4:26 AM
  • User1829879277 posted

    Use Page.Title in the Page_Load event.

    Set the page title by :

    string strPageTitle = "My Page Title"; // Value based on the query

    Page.Title = strPageTitle;

    Tuesday, March 20, 2012 6:11 AM
  • User-2122576196 posted

    I'm not very familiar with the Page_Load event. This is what I'm currently using to grab my page titles from the web.sitemap file:

    Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
        Dim currentNode As SiteMapNode = SiteMap.CurrentNode
        If Not currentNode Is Nothing Then
                Dim subDescription As String = currentNode.Description
                If subDescription.Length = 0 Then subDescription = currentNode.Description
                If subDescription.Length <> 0 And subDescription <> "default" Then
                    Page.Title &= "" & Server.HtmlEncode(subDescription)
                End If
        End If  
      End Sub

    How would I proceed from here?

    Tuesday, March 20, 2012 6:20 AM
  • User1829879277 posted

    Are you getting any error or facing any issue here?

    Tuesday, March 20, 2012 6:33 AM
  • User-2122576196 posted

    No I am not currently getting any errors, however my page title is still not being influenced by the query string. 

    Tuesday, March 20, 2012 6:36 AM
  • User1829879277 posted

    I hope, by page title you mean the string gettign displayed in the Title Bar of the Web Browser.

    For this, the Page.Title should work.

    Have you checked what value is getting in query string?

    Have you tried it by hardcoding the title for testing?

    Tuesday, March 20, 2012 6:45 AM
  • User-2122576196 posted

    Well here's what I would like to do. When I click on the '3D Artwork' on the front page, I would like the new page title to display '3D Artwork'. The current URL is http://darvinkmanwah.com/artwork-tags.aspx?id=3D%20Artwork#TopPage but the page title comes up as Page.Title

    I did try hardcoding it in the web.sitemap file but it still shows up as Page.Title

    Tuesday, March 20, 2012 7:00 AM
  • User1829879277 posted

    On 'artwork-tags.aspx' page, inside Page_Load event, write as shown below:

    Page.Title = Request.QueryString["id"];

    OR, to hardcode the title, set it on the same page as shown below:

    Page.Title = "3D Artwork";
    Tuesday, March 20, 2012 7:16 AM
  • User-2122576196 posted

    For the 'artwork-tags.aspx' page, it is pulling content from the master page using 2 ContentPlaceHolders, one called 'TopBar' and the other 'Article'. At the top of the page it is using the '<%@ Page Language="VB" MasterPageFile="~/MainContent.master" Title="" %>' to pull the Master Page.

    Where on the 'artwork-tags.aspx' page would I add the Page_load event.

    This is what I have currently on the page:

    <%@ Page Language="VB" MasterPageFile="~/MainContent.master" Title="" %>
    
    <asp:Content ID="TopBar" ContentPlaceHolderID="TopBar" Runat="Server"></asp:Content>
    
    <asp:Content ID="Article" ContentPlaceHolderID="Article" Runat="Server"></asp:Content>
    Tuesday, March 20, 2012 10:59 PM
  • User1829879277 posted

    Hi Darvin,

    The code you have posted is of .ASPX page and the Page_Load event handler as well as other event handlers such as Button_Click can be found in the .CS page i.e. code behind page.

    If you are working with C#.Net language then it will be in 'artwork-tags.cs' page and if it is VB.Net then it will be 'artwork-tags.vb' page.

    To open this page, Right-Click in the 'artwork-tags.aspx' page in VS and click 'View Code'.

     

    Wednesday, March 21, 2012 1:11 AM
  • User-2122576196 posted

    Hey Sumit,

    I didn't have a .vb file for the page so I created a new .aspx page for it with the code being in the new vb file. So here is the code I added to the vb file (PS is it recommended for every .aspx page to have a vb file with it because currently I don't, just wondering)

    Partial Class artwork_tags
        Inherits System.Web.UI.Page
    
        Public Sub New()
            Page.Title = "3D Artwork File"
        End Sub
    End Class

    The problem is if I use the above statement it works for the page without a query; and the other piece of code u gave with the query string doesn't work at all. The error reads "Value of the type 'System.Collections.Specialized.NameValueCollection' cannot be converted to 'String'."

    I guess I'm doing something wrong ...

    Wednesday, March 21, 2012 7:07 AM
  • User1829879277 posted

    Try converting it to the String.

    Page.Title = Request.QueryString["id"].ToString()
    Wednesday, March 21, 2012 7:21 AM
  • User-2122576196 posted

    Nope that still didn't work ... Do I need to put something like this or along the lines of this ":

    Page.Title = "Request.QueryString["id"].ToString()"
    Wednesday, March 21, 2012 7:31 AM
  • User1829879277 posted

    Ohh as you are using VB, the statement should be as:

    Page.Title = Request.QueryString("id")

    Here, I replaced the Sqare brackets '[' & ']' with the Round brackets '(' & ')'

    Wednesday, March 21, 2012 7:49 AM
  • User-2122576196 posted

    Hey,

    I made the change but it's not working ... You can see the page here, I'm querying the page using 3D Artwork as the keyword:

    http://darvinkmanwah.com/artwork-tags.aspx?id=3D%20Artwork#TopPage

    Wednesday, March 21, 2012 8:04 AM
  • User1829879277 posted

    Try this:

    void Page_Load(object source, EventArgs e) 
    { 
        Page.Title = Request.QueryString("id")
    }
    
    Wednesday, March 21, 2012 8:48 AM
  • User-2122576196 posted

    This is currently all the vb for the page that I have:

    Partial Class artwork_tags
        Inherits System.Web.UI.Page
    
        Public Sub New()
            Page.Title = "3D Artwork"
        End Sub
    End Class

    I'm using the old script for now but it's just a temp until we figure this out. Could you show me exactly where to put that piece of code, thanks ...

    Wednesday, March 21, 2012 8:56 AM
  • User1829879277 posted

    Partial Class artwork_tags      Inherits System.Web.UI.Page        Public Sub New()          Page.Title = "3D Artwork"      End Sub  End Class

    Replace this with:

    Partial Class artwork_tags 
        Inherits System.Web.UI.Page 
     
        Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
            Page.Title = Request.QueryString("id")
        End Sub 
    End Class
    Wednesday, March 21, 2012 9:01 AM
  • User-2122576196 posted

    Unfortunately, still nothing ... The page is opening now but the title of the page comes up as Page.Title. Do I need to do anything in the web.sitemap?

    http://darvinkmanwah.com/artwork-tags.aspx?id=3D%20Artwork#TopPage

    Wednesday, March 21, 2012 9:12 AM
  • User1829879277 posted

    If you have set the Page.Title in the we.sitemap file then remove it and try.

    Thursday, March 22, 2012 1:40 AM
  • User-2122576196 posted

    Hey,

    I checked the web.sitemap and there is no title associated with the url ... hmmm

    Thursday, March 22, 2012 2:08 AM
  • User1829879277 posted

    Can't predict what exactly happening..

    Kindly search in entire solution for 'Page.Title' and check whether anywhere else it is being set to string "Page.Title".

    Thursday, March 22, 2012 2:19 AM
  • User-2122576196 posted

    Interesting enough I found this on the Master page:

    Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
        Dim currentNode As SiteMapNode = SiteMap.CurrentNode
        If Not currentNode Is Nothing Then
                Dim subDescription As String = currentNode.Description
                If subDescription.Length = 0 Then subDescription = currentNode.Description
                If subDescription.Length <> 0 And subDescription <> "default" Then
                    Page.Title &= "" & Server.HtmlEncode(subDescription)
                End If
        End If  
      End Sub
    Thursday, March 22, 2012 2:31 AM
  • User1829879277 posted

    You may comment the whole code inside the Page_Load event of the Master Page and try...

    Thursday, March 22, 2012 2:41 AM
  • User-2122576196 posted

    Hmm like this:

    <script runat="server">
      Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
        Dim currentNode As SiteMapNode = SiteMap.CurrentNode
        If Not currentNode Is Nothing Then
                Dim subDescription As String = currentNode.Description
                If subDescription.Length = 0 Then subDescription = currentNode.Description
                If subDescription.Length <> 0 And subDescription <> "default" Then
                    Page.Title &= "" & Server.HtmlEncode(subDescription)
                End If
        End If  
        End Sub
        
        Partial Class artwork_tags
            Inherits System.Web.UI.Page
     
            Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs)
                Page.Title = Request.QueryString("id")
            End Sub
        End Class
    </script>
    Thursday, March 22, 2012 2:46 AM
  • User1829879277 posted

    No.. Like this:

    <script runat="server"> 
      Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) 
        'Dim currentNode As SiteMapNode = SiteMap.CurrentNode 
        'If Not currentNode Is Nothing Then 
        '        Dim subDescription As String = currentNode.Description 
        '        If subDescription.Length = 0 Then subDescription = currentNode.Description 
        '        If subDescription.Length <> 0 And subDescription <> "default" Then 
        '            Page.Title &= "" & Server.HtmlEncode(subDescription) 
        '        End If 
        'End If  
    
        Page.Title = Request.QueryString("id") 
    
        End Sub 
    </script>

    And comment the code in the Page_Load event on the artworks_tags.aspx page, like:

        Partial Class artwork_tags 
            Inherits System.Web.UI.Page 
      
            Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) 
                'Page.Title = Request.QueryString("id") 
            End Sub 
        End Class
    Thursday, March 22, 2012 2:58 AM
  • User-2122576196 posted

    Hey Sumit,

    Amazing ... This works, I`m really stoked right now ... and I`m getting the desired result ... but just a few problems else where because of it.

    Firstly it looks as though it`s taking the Page Title information directly from the link itself, correct? because the link is pulling my column called `id` in the database as the page title, which it is not what I really want. I want it to pull the `subject` column in the databse to display as the page title. How would I do that? Can I change that or do I have to go to all my pages and change this:

    <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# "View " & Eval("Subject") & " ..." %>'
    NavigateUrl='<%#"digital-playground/artwork/display.aspx?id=" & DataBinder.Eval(Container.DataItem, "ID") & "#Top" %>' ToolTip='<%# Eval("Subject") %>' />

    to

    <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# "View " & Eval("Subject") & " ..." %>'
    NavigateUrl='<%#"digital-playground/artwork/display.aspx?id=" & DataBinder.Eval(Container.DataItem, "Subject") & "#Top" %>' ToolTip='<%# Eval("Subject") %>' />

    Thanks again Sumit ...

    Thursday, March 22, 2012 5:24 AM
  • User1829879277 posted

    Yes, you can pass the Subject instead of ID of the Artwork. This will require less efforts to implement.

    If you need ID also, then pass the ID too in the querystring.

     

    Thursday, March 22, 2012 6:24 AM
  • User-2122576196 posted

    Hey Sumit,

    Sorry for the long pause, I'm been looking at the pages individually and the code to make some sense of it. I've realized that only the pages that have a query strong in the URL will show as Page Title and all my other pages aren't working. They show localhost:49165/www.darvinkmanwah.com/digital-playground/artwork/default.aspx#Top or whatever else the page might be.

    Is there a way so that I can keep pulling all my page titles from the web.sitemap instead of the query string? The process we are currently using is indeed working for the tags on the artwork-tags.aspc but everything else is getting affected. Any suggestions?

    Thanks ...

    Monday, March 26, 2012 7:19 AM
  • User1829879277 posted

    Hi Darvin,

    Frankly speaking, I am not much familiar with the web.sitemap and not sure whether you will be able to get the current page's title from this.

    Hence, if you are able to get the page title using web.sitemap then you can definitely go ahead with it.

    As per the code you have posted in one of the previous post, I have developed the below code.

    Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) 
        Dim currentNode As SiteMapNode = SiteMap.CurrentNode 
        If Not currentNode Is Nothing Then 
                Dim subDescription As String = currentNode.Description 
                If subDescription.Length = 0 Then subDescription = currentNode.Description 
                If currentNode.Title <> "" Then 
                    Page.Title = currentNode.Title
                End If 
        End If  
    End Sub

    Place this code in the Master Page's code behind and try whether its working or not.

     

    Tuesday, March 27, 2012 1:12 AM
  • User-2122576196 posted

    Hey Sumit,

    I managed to figure out the problem from before. I was pulling from the database the column labelled 'id' and all my ids are like this 'wip-beautiful-disaster' or 'the-far-side' but with the artwork-tags.aspx page, it was not pulling the 'id' but instead it was pulling the column 'subject' which looked like this 'The Far Side' or 'Forest' so I'm guessing the space between the words make a huge difference. Any idea how to fix that?

    Also the vb I had included before is how it links to the web.sitemap file and pulls the titles from there ... kinda neat I think ... Thanks Sumit ...

    Tuesday, March 27, 2012 2:47 AM
  • User1829879277 posted

    I'm guessing the space between the words make a huge difference. Any idea how to fix that?

    I guess you are asking this to use QueryString for Page Title. For this, while assigning value to the querystring, replace the blank spaces with the under-scores. And while assigning the query string value to the Page.Title, replace the under-scores with the blank space.

    Tuesday, March 27, 2012 3:30 AM
  • User-2122576196 posted

    I guess you are asking this to use QueryString for Page Title.

    Actually no .. I managed to get the web.sitemap file to give the titles of the webpage which works great. You can see it over at:

    3D Artwork: http://localhost:49165/www.carphology-entertainment.com/artwork-tags.aspx?id=3D-Artwork#TopPage 

    Work in Progress: http://localhost:49165/www.carphology-entertainment.com/artwork-tags.aspx?id=Work-in-Progress#TopPage

    Thanks alot for helping out with the coding Sumit.

    You can check out the side over at http://www.darvinkmanwah.com and tell me what you think. The code is coming along nicely.

    I think I asked this before but I don't think I got a reply. Should every asp.net page have a vb file, even though there is no vb? Just wondering, thanks ...

    Thursday, April 5, 2012 3:53 AM
  • User1829879277 posted

    Should every asp.net page have a vb file, even though there is no vb?

    No. I is not necessary to always have a .vb (.cs in case of C#.Net) file for every ASP.Net page. If there is no server side coding and the page is just for static data then no need of .vb file. In this case instead of .axpx page you may use .html page also.

    Even you may write the server side coding in .aspx page only using <script> and </script> tags. But, it is not advisable as it reduces the code management and code debugging efficiency.

    By the way, your site is looking superb!! Great design and color combinations.

    Congrats !!

    Friday, April 6, 2012 1:41 AM
  • User-2122576196 posted

    Would you recommend having both html and aspx pages work together? Would is cause any problems or is it ok to do that?

    Thanks alot for your kinda words Sumit. I've been working on it for quite some time especially coding and designing. I'm now adding more content and keeping it updated. Thanks again though ...

    Friday, April 6, 2012 3:54 AM
  • User1829879277 posted

    Sure. You may have both HTML and ASPX pages in your application. There is absolutely no problem with it.

    Just one issue is there that the HTML pages cann't interact with the ASPX or any server pages. HTML pages can be used to display the static data and provide links to other pages.

    Friday, April 6, 2012 7:25 AM
  • User-2122576196 posted

    Yah that sounds great ... I might end up using the html just for the static stuff and have the aspx pages for the dynamic data I'm pulling for the database ...

    I'm curently working on the URL rewriting and fixing some query problems on the artwork-tags.aspx page ... but that's again ...

    Saturday, April 7, 2012 4:19 AM