我尝试使用 itemcommand 函数创建一个数据列表,尽管由于某种原因,该程序似乎没有进入 itemcommand 的函数。
aspx
<asp:DataList ID="DataList1" runat="server" OnItemCommand="DataList1_ItemCommand" DataKeyField="jobID">
<ItemTemplate>
<div class="jobContainer">
<div class="jobDetails">
<span class="jobName"><%# Eval("jobName") %></span><br />
<hr class="style13">
<a class="Details"> <b>Requirments: </b><span ><%# Eval("jobRequirments") %> WPM</span> </a>
<a class="Details"> <b>Salary: </b><span ><%# Eval("jobSalary")%> Shekel per hour</span> </a>
<a class="Details"> <b>City: </b><span ><%# Eval("jobCity")%></span>
<asp:Button ID="Button1" runat="server" CommandName="Details" Text="Show Details" />
</div>
</div>
</ItemTemplate>
</asp:DataList>
代码背后:
protected void Page_Load(object sender, EventArgs e)
{
// getjobs returns a dataset
Service.Service a = new Service.Service();
DataList1.DataSource = a.getjobs();
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Details")
{
Response.Redirect("Home.aspx");
}
}