Solved

DataNavigateUrlFormatString= only ever seems to open first record in dataset

Posted on 2012-03-16
8
604 Views
Last Modified: 2012-03-16
I have created an ASP:Hyperlink field that turns the User Name field of my results page into a link. That works fine.
I have created a DataNavigateUrlFormatString= tag (is it a tag?) in the field to open a seperate ASPX page, which should list the details for that record.
However, no matter what I try, the link will only ever open the new page and display the first record in the dataset - even though the link when hovered or opened shows the correct information (e.g. shows a destination of http://ho-nas/guestbook2/tryread.aspx?Username=Bloggs,%20Joe)
Here is the code. (If any of the fields are duplicated that's because I've tried several ways of doing it and haven't deleted them, so they're an unintentional error on my part!)

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.Oledb" %>

<!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 id="Head1" runat="server">
    <title>List of ALL Assets on Database</title>
    <link href="Styles/Site.css" rel="stylesheet" type="text/css" /></head>
<body>
'(There is a list of hyperlinks to other pages here - but they're not important, so I've removed them!)
    <form id="form1" runat="server">
    <div>

        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="AccessDataSource1">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" Visible="False" />
                    <asp:HyperLinkField
    DataNavigateUrlFields="username"
    DataNavigateUrlFormatString="tryread.aspx?Username={0}"
    DataTextField="UserName"
    HeaderText="User Name"
    SortExpression="UserName" />
                <asp:BoundField DataField="Make" HeaderText="Make" SortExpression="Make" />
                <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
                <asp:BoundField DataField="Serial" HeaderText="Serial" 
                    SortExpression="Serial" />
                <asp:BoundField DataField="Acquired" HeaderText="Acquired" 
                    SortExpression="Acquired" DataFormatString="{0:d MMMM yyyy}" />
                <asp:BoundField DataField="Expires" HeaderText="Expires" 
                    SortExpression="Expires" DataFormatString="{0:d MMMM yyyy}" />
                <asp:BoundField DataField="Condition" HeaderText="Condition" 
                    SortExpression="Condition" />
                <asp:BoundField DataField="Comments" HeaderText="Comments" 
                    SortExpression="Comments" />
                <asp:CheckBoxField DataField="Retired" HeaderText="Retired" 
                    SortExpression="Retired" />
            </Columns>
        </asp:GridView>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/guestbook2/App_Data/TWIT.mdb" SelectCommand="SELECT * FROM [Requests]">
        </asp:AccessDataSource>

        </div>
    </form>
  </body>
</html>

Open in new window


I know it's bound to be something simple, but I don't know what!!!
0
Comment
Question by:winstalla
  • 5
  • 3
8 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 37728683
Can you show how you load the detail-info in your page ? Do you use the incoming querystring-parameters to filter to the correct record ?
0
 

Author Comment

by:winstalla
ID: 37728708
I'm afraid that I have no idea!

The code supplied is the entire code from the list page, which simply lists the data in the dataset. The second page (tryread.aspx) is below if that helps:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.Oledb" %>

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

<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim Connection As OledbConnection
        Connection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" & _
        "Data Source=E:\Company\New_intranet\Guestbook2\App_Data\twit.mdb")
        Connection.Open()
        Dim Command As OleDbCommand
        Command = New OleDbCommand("SELECT * FROM requests", Connection)
        Dim DataReader As OleDbDataReader
        '        DataReader = Command.ExecuteReader()
        '       GridView1.DataSource = DataReader
  '      GridView1.DataBind()
       
        Connection.Close()
              
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Read Single Data Record</title>
    <link href="Styles/Site.css" rel="stylesheet" type="text/css" /></head>
<body>
    <form id="form1" runat="server">
<p Align="center">| <a href="acc_form_insert.aspx">Add a Record Form</a> | <a href="acc_insert.aspx">Access Insert</a> | <a href="acc_search.aspx">Search for Records</a> | <a href="acc_upd.aspx">Update Records</a> | <a href="acc_read.aspx">List Records</a> | <a href="iterate_records.aspx">Iterate Records</a> | <a href="tryread.aspx">My Try</a> |</p>
<p Align="center">| <a href="db_count.aspx">Database Count</a> | <a href="dataset_count.aspx">Dataset Count</a> |



    <asp:FormView ID="FormView1" runat="server" AllowPaging="True" 
        DataKeyNames="ID" DataSourceID="AccessDataSource1">
        <EditItemTemplate><TABLE border="3" cellpadding="1">
            <TR><td>ID:<TD>
            <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' /></TR>
            </TABLE>
            <br />
            Make:
            <asp:TextBox ID="MakeTextBox" runat="server" Text='<%# Bind("Make") %>' />
            <br />
            Username:
            <asp:TextBox ID="UsernameTextBox" runat="server" 
                Text='<%# Bind("Username") %>' />
            <br />
            Comments:
            <asp:TextBox ID="CommentsTextBox" runat="server" 
                Text='<%# Bind("Comments") %>' />
            <br />
            Model:
            <asp:TextBox ID="ModelTextBox" runat="server" Text='<%# Bind("Model") %>' />
            <br />
            Serial:
            <asp:TextBox ID="SerialTextBox" runat="server" Text='<%# Bind("Serial") %>' />
            <br />
            Retired:
            <asp:CheckBox ID="RetiredCheckBox" runat="server" 
                Checked='<%# Bind("Retired") %>' />
            <br />
            Acquired:
            <asp:TextBox ID="AcquiredTextBox" runat="server" 
                Text='<%# Bind("Acquired") %>' />
            <br />
            Expires:
            <asp:TextBox ID="ExpiresTextBox" runat="server" Text='<%# Bind("Expires") %>' />
            <br />
            Condition:
            <asp:TextBox ID="ConditionTextBox" runat="server" 
                Text='<%# Bind("Condition") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Update" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>
        <InsertItemTemplate>
            Make:
            <asp:TextBox ID="MakeTextBox" runat="server" Text='<%# Bind("Make") %>' />
            <br />
            Username:
            <asp:TextBox ID="UsernameTextBox" runat="server" 
                Text='<%# Bind("Username") %>' />
            <br />
            Comments:
            <asp:TextBox ID="CommentsTextBox" runat="server" 
                Text='<%# Bind("Comments") %>' />
            <br />
            Model:
            <asp:TextBox ID="ModelTextBox" runat="server" Text='<%# Bind("Model") %>' />
            <br />
            Serial:
            <asp:TextBox ID="SerialTextBox" runat="server" Text='<%# Bind("Serial") %>' />
            <br />
            Retired:
            <asp:CheckBox ID="RetiredCheckBox" runat="server" 
                Checked='<%# Bind("Retired") %>' />
            <br />
            Acquired:
            <asp:TextBox ID="AcquiredTextBox" runat="server" 
                Text='<%# Bind("Acquired") %>' />
            <br />
            Expires:
            <asp:TextBox ID="ExpiresTextBox" runat="server" Text='<%# Bind("Expires") %>' />
            <br />
            Condition:
            <asp:TextBox ID="ConditionTextBox" runat="server" 
                Text='<%# Bind("Condition") %>' />
            <br />
            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                CommandName="Insert" Text="Insert" />
            &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </InsertItemTemplate>
        <ItemTemplate>
            <!--ID:-->
            <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' visible="false"/>
            <br />
            Make:
            <asp:Label ID="MakeLabel" runat="server" Text='<%# Bind("Make") %>' />
            <br />
            Username:
            <asp:Label ID="UsernameLabel" runat="server" Text='<%# Bind("Username") %>' />
            <br />
            Model:
            <asp:Label ID="ModelLabel" runat="server" Text='<%# Bind("Model") %>' />
            <br />
            Serial:
            <asp:Label ID="SerialLabel" runat="server" Text='<%# Bind("Serial") %>' />
            <br />
            Condition:
            <asp:Label ID="ConditionLabel" runat="server" Text='<%# Bind("Condition") %>' />
            <br />
            Acquired:
            <asp:Label ID="AcquiredLabel" runat="server" 
                Text='<%# Bind("Acquired", "{0:D}") %>' />
            <br />
            Expires:
            <asp:Label ID="ExpiresLabel" runat="server" 
                Text='<%# Bind("Expires", "{0:D}") %>' />
            <br />
            Comments:
            <asp:Label ID="CommentsLabel" runat="server" Text='<%# Bind("Comments") %>' />
            <br />
            Retired:
            <asp:CheckBox ID="RetiredCheckBox" runat="server" 
                Checked='<%# Bind("Retired") %>' Enabled="false" />
            <br />

        </ItemTemplate>
    </asp:FormView>
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="E:\Company\New_intranet\Guestbook2\App_Data\twit.mdb" SelectCommand="SELECT * FROM [Requests]">
    </asp:AccessDataSource>
    </form>



  </body>
</html>

Open in new window

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 37728721
Am I correct that if you go to the details page that you always get the same user (the first one in the datatable) ?
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:winstalla
ID: 37728727
Yes. Even though the tryread.aspx page opens up with the correct User Name in the address, it only ever displays the details of the first record in the Access Database.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 300 total points
ID: 37728736
Passing variables between pages using QueryString
http://www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString

Try to change this
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
        DataFile="E:\Company\New_intranet\Guestbook2\App_Data\twit.mdb" SelectCommand="SELECT * FROM [Requests]">
    </asp:AccessDataSource>

into
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
        DataFile="E:\Company\New_intranet\Guestbook2\App_Data\twit.mdb"   SelectCommand="SELECT * FROM [Requests]
                 WHERE UserName = @userName">
  <SelectParameters>
    <asp:QueryStringParameter Name="userName" QueryStringField="userName" />
  </SelectParameters>
</asp:SqlDataSource>


Source: http://msdn.microsoft.com/en-us/library/xt50s8kz.aspx
0
 

Author Comment

by:winstalla
ID: 37728757
This leaves the Record List page completely empty. No records are retrieved from the Database at all!
0
 

Author Comment

by:winstalla
ID: 37728803
OK! Dozy Award time!
I changed the line, as suggested - but on the WONG PAGE! D'oh!
Now that I've changed it on the RESULTS page (and not the list page, like I did initially!) it works!!!!! Thanks!!!!!
0
 

Author Closing Comment

by:winstalla
ID: 37728811
Once you put the change on the right page it works! Put it on the wrong page and it doesn't - but then I guess you wouldn't expect it to.
So all blame for the fact that it didn't work initially goes to the pillock who put the fix on the wrong page - me!
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This video teaches users how to migrate an existing Wordpress website to a new domain.

730 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