我的项目模板中有一个按钮,我想对其进行编程,以便将我引导至特定的工作详细信息
Posted
技术标签:
【中文标题】我的项目模板中有一个按钮,我想对其进行编程,以便将我引导至特定的工作详细信息【英文标题】:I have a button in my item template and I want to program it so that it directs me to that specific job details 【发布时间】:2020-11-27 13:32:28 【问题描述】:我有一个列出所有工作的页面。我必须编写一个按钮,以便当我单击它时,它会将我引导至特定的工作详细信息。我怎样才能做到这一点。我已经尝试过 navigateUrl,但是当我点击按钮时,什么也没有发生。
这是我的项目模板代码
<asp:ListView ID="lsvJob" runat="server">
<ItemTemplate>
<div class="nf-item branding coffee spacing">
<div class="col-md-6 col-lg-4 mb-30">
<div class="service_box">
<figure>
<asp:Image ID="imgposter" ImageUrl='<%# Eval("HO_Image", "~/Images/0") %>'
runat="server" Height="300px" Width="300px" ImageAlign="Top" />
</figure>
<h3><%#Eval("Job_Name") %></h3>
<p>
<b>Employer Name:</b> <%# Eval("HO_LastName") %> <%# Eval("HO_FirstName") %>
<br />
<b>Email Address:</b> <%# Eval("HO_Email") %>
</p>
<asp:LinkButton ID="lnkmovdetails" runat="server" Text="View Details"
NavigateUrl='<%# Eval("Job_ID","~/jobdetails.aspx?id=0")%>' CommandName="btnAccess" CssClass="btn btn-info"></asp:LinkButton>
</div>
</div>
</div>
</ItemTemplate>
</asp:ListView>
背后的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Configuration;
using System.Data.SqlClient;
namespace moCoolMaid
public partial class listjob : System.Web.UI.Page
private string _conString =
WebConfigurationManager.ConnectionStrings["MaidCS"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
// Create Connection
using (SqlConnection con = new SqlConnection(_conString))
// Create Command
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = " SELECT tblHO.*, tblJob.* FROM tblHO, tblJob WHERE tblJob.HO_ID=tblHO.HO_ID";
//Create DataReader
SqlDataReader reader;
con.Open();
reader = cmd.ExecuteReader();
//Bind the reader to the repeater control
lsvJob.DataSource = reader;
lsvJob.DataBind();
con.Close();
我的 jobdetail 网络表单中的代码
<asp:DetailsView ID="dsvJob" runat="server" AutoGenerateRows="False" DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="10" GridLines="Vertical">
<AlternatingRowStyle BackColor="Gainsboro" />
<EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<Fields>
<asp:BoundField DataField="Job_Name" HeaderText="Job_Name" SortExpression="Job_Name" />
<asp:BoundField DataField="Job_Desc" HeaderText="Job_Desc" SortExpression="Job_Desc" />
<asp:BoundField DataField="Job_Salary" HeaderText="Job_Salary" SortExpression="Job_Salary" ItemStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Deadline_Date" HeaderText="Deadline_Date" SortExpression="Deadline_Date" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Min_Experience" HeaderText="Min_Experience" SortExpression="Min_Experience" />
<asp:BoundField DataField="Min_Qualification" HeaderText="Min_Qualification" SortExpression="Min_Qualification" />
</Fields>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MaidCS %>" SelectCommand="SELECT [Job_Name], [Job_Desc], [Job_Salary], [Deadline_Date], [Type], [Min_Experience], [Min_Qualification] FROM [tblJob]"></asp:SqlDataSource>
【问题讨论】:
【参考方案1】:从 LinkButton 和以下一个中删除 navigateUrl 属性。
PostBackUrl="imagepage.aspx?v=<%#Eval("id") %>"
从查询字符串你会得到jobID。读取 JobId 并显示记录。
谢谢,希望对你有帮助:)
【讨论】:
【参考方案2】:命令名称不能这样工作。使用以下代码进行重定向
<asp:LinkButton ID="lnkmovdetails" runat="server" Text="View Details" PostBackUrl='~/jobdetails.aspx?id=<%#Eval("Job_ID") %>' CssClass="btn btn-info" />
【讨论】:
以上是关于我的项目模板中有一个按钮,我想对其进行编程,以便将我引导至特定的工作详细信息的主要内容,如果未能解决你的问题,请参考以下文章