0

ユーザーがクリックしたダイナミック リンク ボタンの 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();
                    
                }

ここに画像の説明を入力

ここでは 2 つの行が表示されており、ユーザーが最初の行をクリックした場合

  • 「この仕事に応募する」

    EmployeeJobTagging テーブルに挿入される行が 1 行だけになるように、ID を「1」にしてデータベースに渡したいと考えています。ただし、ここでは両方の行がそれぞれ ID= 1 と 2 で挿入されています。

以下をご覧ください。

ここに画像の説明を入力

親切に助けてください。

4

0 に答える 0