如何知道动态链接按钮的ID?

时间:2013-08-11 07:58:31

标签: c# asp.net

我编写了一个代码来检索用户点击的动态链接按钮的ID。但是,它显示所有链接按钮的ID。

请检查我的代码。

 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.OnClientClick = "return RedirectTo('" + id + "');";
                               lbView.ID = "linkButton" + readerrowcount;
                               ID = readerrowcount;

                               tc.Controls.Add(lbView);
                               tr.Cells.Add(tc);


                            }

                            tbl.Rows.Add(tr);



                            string query = "INSERT INTO EmployeeJobTagging VALUES('" +ID + "','" + id + "','"+jobId+"','"+JobDesignation+"')";
                            SqlCommand sqlCmd = new SqlCommand(query, con);
                            sqlCmd.ExecuteNonQuery();
                        }
                        ViewState["dynamictable"] = true; 
                      } reader.NextResult();

                }

enter image description here

这里我显示了两行,如果用户点击了第一行

  • “申请这份工作”

    我希望将ID传递给数据库“1”,以便在EmployeeJobTagging表中只插入一行。但是这两行分别插入ID = 1和2。

请在下面找到。

enter image description here

请给我一些帮助。

0 个答案:

没有答案