Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now