Link to home
Start Free TrialLog in
Avatar of BOEING39
BOEING39

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BOEING39
BOEING39

ASKER

That did it, thanks for the assistance.
Excellant
Glad to help :-)