Solved

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

Posted on 2011-02-13
4
671 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
  • 2
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 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