Solved

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

Posted on 2011-02-13
4
674 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 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net background worker crossthread 11 43
VB.net Is there code behind PowerPivot 2 70
Convert VB web project to C# 3 66
VB .net 2010 Byte array 2 21
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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