请参阅以下代码。 Home.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="WebApplication1.Home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="XmlDataSource1"
DataTextField="Name" DataValueField="Description"
DisplayMode="HyperLink" OnClick="BulletedList1_Click"></asp:BulletedList>
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
<Data>
<pagelifecycle>
<Step Name="Page Request" Description ="The Page Request occurs before page life cycle begins. When Page is requested by the user, ASP.NET determines whether the page needs to be parsed and compiled or whether the cached version of the page can be sent in response without running the page."></Step>
</pagelifecycle>
</Data>
</asp:XmlDataSource>
<asp:TextBox ID="Description" TextMode="MultiLine" Rows="10" Columns ="250" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
Home.aspx.cs
using System;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class Home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BulletedList1_Click(object sender, BulletedListEventArgs e)
{
Description.Text = BulletedList1.Items[e.Index].Value.ToString();
}
}
}
当我运行此页面时,它会出现以下错误,
HTTP错误404.0 - 未找到
您要查找的资源已被删除,名称已更改或暂时不可用。
为什么会出现这个错误以及我错过了什么?
答案 0 :(得分:0)
将显示模式HYPERLINK更改为LINKBUTTON。它应该工作。
<asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="XmlDataSource1"
DataTextField="Name" DataValueField="Description"
DisplayMode="LinkButton" OnClick="BulletedList1_Click">
</asp:BulletedList>
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
<Data>
<pagelifecycle>
<Step Name="Page Request" Description ="The Page Request occurs before page life cycle begins. When Page is requested by the user, ASP.NET determines whether the page needs to be parsed and compiled or whether the cached version of the page can be sent in response without running the page."></Step>
</pagelifecycle>
</Data>
</asp:XmlDataSource>
<asp:TextBox ID="Description" TextMode="MultiLine" Rows="10" Columns="250" runat="server"></asp:TextBox>