Solved

DataNavigateUrlFormatString= only ever seems to open first record in dataset

Posted on 2012-03-16
8
600 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:winstalla
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 53

Accepted Solution

by:
Dhaest earned 300 total points
Comment Utility
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
Comment Utility
This leaves the Record List page completely empty. No records are retrieved from the Database at all!
0
 

Author Comment

by:winstalla
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Read about why website design really matters in today's demanding market.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

763 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

16 Experts available now in Live!

Get 1:1 Help Now