简体   繁体   中英

How to hyperlink list from Access database in C# ASP.Net

My assignment states: Create a site that is similar to Figure 8.9 in ASP.NET 4 Unleashed, but instead of a list of movie hyperlinks, create a list of your favorite activities (sports, reading, shopping etc.) The image in question is just a simple vertical listing of hyperlinked movies. I am running into issues as it will not build correctly though I have no errors or warnings. I do have a message that states

"Message 1 Validation (ASP.Net): Attribute 'ConnectionString' is not a valid attribute of element 'AccessDataSource'. c:\\users\\owner\\documents\\visual studio 2010\\Projects\\Activities\\Activities\\Activities.aspx 41 5 Activities"

My code is as follows

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Activities.aspx.cs"
Inherits="Activities.Activities" %>

<!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">
<style type="text/css">
    .floater
    {
        float:left;
        border:solid 1px black;
        padding:5px;
        margin:5px;
    }
</style>
    <title>Activities</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Repeater
    id="Repeater1"
    DataSourceId="srcActivities"
    Runat="server">
    <ItemTemplate>

    <asp:HyperLink
    id="HyperLink1"
    Text='<%# Eval("Type") %>'
    NavigateUrl='<%# Eval("Activities.aspx?id={0}") %>'
    runat="server" />

    <br />
    </ItemTemplate>
    </asp:Repeater>

    <asp:AccessDataSource
    id="srcActivities"
    ConnectionString="Data Source=.\Access;
    AttachDbFilename=|Desktop|WD364|Activities.accdb;
    Integrated Security=True;User Instance=True"
    SelectCommand="SELECT Id, Type FROM Activities"
    Runat="server" />

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

The database is a simple MS Access Table (there is only one) with a few rows and two columns. One the ID and one the Type with the names of the activities. Any help would be greatly apprecitated

Try this

  <asp:hyperlink id="hlxx" runat="server" 
       NavigateUrl='<%# "~/Activities.aspx?id="+Eval("Type") %>' 
        Target='<%# "_blank" %>'>Eval("Type")</asp:hyperlink>

Or see this Send string with QueryString in Repeater Control in ASP.net

and below link have multiple answers

Link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM