Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GridView Hyperlink REDIRECTS TO NEW PAGE BUT NOT DISPLAYING CORRECT ROW DATA

Posted on 2011-02-13
4
Medium Priority
?
676 Views
Last Modified: 2012-05-11
Hi, hope someone can help

I have a page displaying a GridView of contents with a hyperlink and I want to display contents of a hyperlink row on another page in a DetailsView

The database is a simple MSAccess three columned table called News: 'NewsID', 'ArticleTitle','Article'

News1.aspx will list 'NewsID' and 'ArticleTitle' I have also included an extra column containing the hyperlink 'More...'
News2.aspx should be displaying 'ArticleTiltle' and 'Article' once hyperlink is clicked.

The GridView table in News1.aspx is configured thus:

<asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1" Style="position: static" AutoGenerateColumns="False" DataKeyNames="NewsID">
<Columns>
<asp:BoundField DataField="NewsID" HeaderText="NewsID" InsertVisible="False" ReadOnly="True"
SortExpression="NewsID" HtmlEncode="False" />
<asp:BoundField DataField="ArticleTitle" HeaderText="ArticleTitle" SortExpression="ArticleTitle" HtmlEncode="False" />
<asp:HyperLinkField DataNavigateUrlFields="NewsID" DataNavigateUrlFormatString="News2.aspx?NewsID={0}"
DataTextField="ArticleTitle" HeaderText="More" Text="More" />
</Columns>
</asp:GridView>

The table displays ok and the link opens News2.aspx, BUT DISPLAYS THE SAME DATA FOR FOR EACH ROW. INSTEAD OF SELECTED ROW.

"I believe the problem lies with my select statement which I am having diffcult setting up .....


In News2.aspx I have inserted a DetailsView table and created a datasource to the Access 'News.mdb' database but this just displays it's own record instance rather than displaying the data related to the NewsID row in the DataView table on News1.aspx.

Appreciate any advice as I am at a loss!
Page 1

Page Language="VB" AutoEventWireup="false" CodeFile="News1.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1" Style="position: static" AutoGenerateColumns="False" DataKeyNames="NewsID">
            <Columns>
                <asp:BoundField DataField="NewsID" HeaderText="NewsID" InsertVisible="False" ReadOnly="True"
                    SortExpression="NewsID" HtmlEncode="False" />
                <asp:BoundField DataField="ArticleTitle" HeaderText="ArticleTitle" SortExpression="ArticleTitle" HtmlEncode="False" />
                <asp:HyperLinkField DataNavigateUrlFields="NewsID" DataNavigateUrlFormatString="News2.aspx?NewsID={0}"
                    DataTextField="ArticleTitle" HeaderText="More" Text="More" />
            </Columns>
        </asp:GridView>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="App_Data.mdb" SelectCommand="SELECT [NewsID], [ArticleTitle], [Article] FROM [News]" >
			<SelectParameters>
				
			</SelectParameters>
			<SelectParameters>
				
			
			</SelectParameters>
		</asp:AccessDataSource>
    
    </div>
    </form>
</body>
</html>


Page 2

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="News2.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" Height="50px" Style="position: static" 
            Width="125px" DataKeyNames="NewsID" DataSourceID="AccessDataSource1">
            <Fields>
                <asp:BoundField DataField="NewsID" HeaderText="NewsID" InsertVisible="False" ReadOnly="True"
                    SortExpression="NewsID" HtmlEncode="False" />
                <asp:BoundField DataField="ArticleTitle" HeaderText="ArticleTitle" SortExpression="ArticleTitle" HtmlEncode="False" />
                <asp:BoundField DataField="Article" HeaderText="Article" SortExpression="Article" HtmlEncode="False" />
            </Fields>
        </asp:DetailsView>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="App_Data.mdb"
            SelectCommand="SELECT [NewsID], [ArticleTitle], [Article] FROM [News]">
		</asp:AccessDataSource>
        &nbsp;
    
    </div>
    </form>
</body>
</html>

Open in new window

App-Data.mdb
News1.aspx
News2.aspx
0
Comment
Question by:BOEING39
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 34883605
Try the attached file



News2.aspx
0
 

Author Comment

by:BOEING39
ID: 34885044
That did it, thanks for the assistance.
0
 

Author Closing Comment

by:BOEING39
ID: 34885052
Excellant
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34887105
Glad to help :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question