我正在我的应用程序中创建一个职位列表页面。我有一个要求,比如求职者点击FIND JOBS 按钮,就会列出工作。我正在创建用于显示作业的动态表。我为求职者的每个表都有一个动态链接按钮,用于申请他选择的工作。
aspx 页面
<script type="text/javascript">
function RedirectTo(id) {
window.location.href = 'ApplyJobsByCandidate.aspx?id=' + id;
return false;
}
</script>
<table>
<tr>
<td>
<asp:DropDownList ID="ddlFilter" runat="server" CssClass="searchMainbtn" ForeColor="White" OnSelectedIndexChanged="ddlFilter_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
</td>
<td>
<asp:Button ID="btnFindJobs" runat="server" Text="Find Jobs" CssClass="searchMainbtn" Width="103px" OnClick="btnFindJobs_Click" />
</td>
<td>
<asp:Label runat="server" Width="388px" ></asp:Label>
</td>
<td>
<asp:Label runat="server" ID="lblName" ForeColor="Crimson" Width="205px"></asp:Label>
</td>
<td>
<asp:LinkButton runat="server" ID="lbLogOut" Text="Log Out" OnClick="lbLogOut_Click" ForeColor="White" Font-Underline="false" CssClass="searchMainbtn" Width="103px" Height="20px"></asp:LinkButton>
</td>
</tr>
</table>
<div> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder></div>
aspx.cs 页面
if (!Page.IsPostBack)
{
fillDropDownList();
lblError.Visible = false;
hlError.Visible = false;
}
if (Page.IsPostBack)
{
lblError.Visible = false;
hlError.Visible = false;
industryName = ddlFilter.SelectedItem.Text.ToString();
lblJobName.Text = industryName.ToUpper() + " JOBS";
this.Rows = getTableRows();
this.Columns = Int32.Parse("1");
}
public void fillDropDownList()
{
SqlDataAdapter da = new SqlDataAdapter("select * from [OfinityJobSearch].[dbo].[tm_TargetedIndustry]", con);
DataTable dt = new DataTable();
da.Fill(dt);
ddlFilter.DataSource = dt;
ddlFilter.DataTextField = "s_IndustryName";
ddlFilter.DataValueField = "s_ID";
ddlFilter.DataBind();
ddlFilter.Items.Insert(0, "Filter Jobs");
da.Dispose();
con.Close();
}
protected void btnFindJobs_Click(object sender, EventArgs e)
{
this.Rows = getTableRows();
this.Columns = Int32.Parse("1");
if (this.Rows == 0)
{
CreateANullTable();
}
else
{
PlaceHolder1.Controls.Clear();
getJobAdsBasedonFilter();
}
}
public void getJobAdsBasedonFilter()
{
SqlCommand cmd = new SqlCommand();
int ID = 0;
try
{
cmd.Connection = con;
cmd.CommandText = "SELECT TOP(10) s_JobDesignation,s_JobDescription,s_NoOfVacancies,s_DatePosted,s_JobId FROM [OfinityJobSearch].[dbo].[tx_ListOfJobs] WHERE s_IndustryName='" + industryName + "' ORDER BY s_JobId ASC ";
cmd.CommandType = CommandType.Text;
if (cmd.Connection.State == ConnectionState.Closed)
cmd.Connection.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
JobDesignation = reader.GetString(0);
JobDescription = reader.GetString(1);
NoOfVacancies = Convert.ToString(reader.GetInt32(2));
DatePosted = Convert.ToString(reader.GetDateTime(3)).Replace("00:00:00", "");
jobId = reader.GetString(4);
int tblRows = 1;
int tblCols = 1;
Table tbl = new Table();
PlaceHolder1.Controls.Add(tbl);
for (int i = 0; i < tblRows; i++)
{
readerrowcount = readerrowcount + 1;
TableRow tr = new TableRow();
tr.CssClass = "rowStyle1";
for (int j = 0; j < tblCols; j++)
{
TableCell tc = new TableCell();
tc.CssClass = "cellStyle1";
System.Web.UI.WebControls.Label txtBox = new System.Web.UI.WebControls.Label();
txtBox.Text = "Job ID:" + jobId + "<br />" + "Job Designation:" + JobDesignation + "<br />" + "Job Description:" + JobDescription + "<br />" + "Vacancies:" + NoOfVacancies + "<br />" + "Ad Posted On:" + DatePosted + "<br />"+"";
tc.Controls.Add(txtBox);
tr.Cells.Add(tc);
System.Web.UI.WebControls.LinkButton lbView = new System.Web.UI.WebControls.LinkButton();
lbView.Text = "<br />" + "Apply for this Job";
lbView.Click += new EventHandler(lbView_Click);
lbView.OnClientClick = "return RedirectTo('" + id + "');";
lbView.ID = "linkButton" + readerrowcount;
tc.Controls.Add(lbView);
tr.Cells.Add(tc);
}
tbl.Rows.Add(tr);
}
ViewState["dynamictable"] = true;
} reader.NextResult();
}
}
}
catch (SqlException exception)
{
MessageBox.Show(exception.Message, "warning!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
}
finally
{
if(cmd.Connection.State==ConnectionState.Open)
cmd.Connection.Close();
cmd.Dispose();
}
}
protected void lbView_Click(object sender, EventArgs e)
{
}
问题是,当求职者单击“查找工作”按钮时,会列出工作,但“申请此工作”根本没有触发。
请帮忙。