Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何知道动态链接按钮的id?_C#_Asp.net - Fatal编程技术网

C# 如何知道动态链接按钮的id?

C# 如何知道动态链接按钮的id?,c#,asp.net,C#,Asp.net,我已经编写了一个代码来检索用户单击的动态链接按钮的id。但是,它会显示所有链接按钮的id 请检查我的密码 if (reader.HasRows) { while (reader.Read()) { JobDesignation = reader.GetString(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();
                    
                }
if(reader.HasRows)
{
while(reader.Read())
{
JobDesignation=reader.GetString(0);
JobDescription=reader.GetString(1);
noofvacarces=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;
表tbl=新表();
占位符1.控件.添加(待定);
对于(int i=0;i“+”职务指定:“+Job指定+”
“+”职务描述:“+Job描述+”
“+”职位空缺:“+Noofvacances+”
“+”广告发布于:“+DatePosted+”
“+”; tc.Controls.Add(txtBox); tr.Cells.Add(tc); System.Web.UI.WebControls.LinkButton lbView=new System.Web.UI.WebControls.LinkButton(); lbView.Text=“
”+“申请这份工作”; lbView.OnClientClick=“返回重定向到(“+id+”);”; lbView.ID=“linkButton”+readerrowcount; ID=readerrowcount; tc.Controls.Add(lbView); tr.Cells.Add(tc); } tbl.行.添加(tr); string query=“插入EmployeeJobTagging值(“+ID+”、“+ID+”、“+jobId+”、“+JobDesignation+”)”; SqlCommand sqlCmd=新的SqlCommand(查询,con); sqlCmd.ExecuteNonQuery(); } ViewState[“dynamictable”]=true; }reader.NextResult(); }

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

  • “申请这份工作”

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

请在下面找到


请给我一些帮助。

当您从数据库加载记录并动态创建控件时,为什么要插入
INSERT
?只有当用户点击链接时,我才会这样做。此代码位于何处?linkButton的Click事件根本没有触发。这就是我尝试执行上述方法的原因。lbView.Click根本没有启动。它没有启动,因为您最迟需要在
页面加载
中的每次回发上使用与以前相同的ID重新创建所有动态控件。事件处理程序太晚了。为什么不使用web数据绑定控件,如
Repeater
?我不知道中继器是什么。