动态生成的table中需要给对应行的label赋值,高手请进来看看!
for (int i = 0; i < nums; i++)
{
tr = new TableRow();
for (int j = 0; j < 1; j++)
{
tc = new TableCell();
tc.Text = dst.Tables[0].Rows[i][j].ToString();
tr.Cells.Add(tc);
}
tc = new TableCell();
LinkButton lkbtn = new LinkButton();
lkbtn.ID = tp + Convert.ToString(i);
lkbtn.Text = "记录时间";
lkbtn.Click += new EventHandler(lkbtn_Click);
tc.Controls.Add(lkbtn);
tr.Cells.Add(tc);
tc = new TableCell();
lbltxt = new Label();
lbltxt.Text = " ";
tc.Controls.Add(lbltxt);
tr.Cells.Add(tc);
tb.Rows.Add(tr);
}
dst.Dispose();
}
protected void lkbtn_Click(object sender, EventArgs e)
{
LinkButton btn = sender as LinkButton;
btn.Text = "∨";
lbltxt.Text = DateTime.Now.ToString();
注:以上为代码,已经实现了,点击“lkbtn_click"后,对应行的text变为∨,但lbltxt.text的值始终不能给对应行赋值,而是给最后一后的那一列“时间”赋值,不知道如何改,请求高人指点,这里多谢了!!
效果如下图
------解决方案--------------------
protected void lkbtn_Click(object sender, EventArgs e)
{
LinkButton btn = sender as LinkButton;
btn.Text = "∨";
TableCell c = (btn.Parent.Parent as TableRow).Cells[2];
Label x = c.Controls[0] as Label;
x.Text = DateTime.Now.ToString();
}