我正在生成动态表格(testtable
),同时我在每行的最后一列中生成LinkButton
,当我点击它时不会被触发。 all("Users")
返回DataTable
。请帮助。
标记
<asp:UpdatePanel ID="MainUpdatePanel" runat="server" Visible="false">
<ContentTemplate>
<asp:Table ID="testTable" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
代码
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
TableHeaderRow tHeaderRow = new TableHeaderRow();
tHeaderRow.TableSection = TableRowSection.TableHeader;
testTable.Rows.Add(tHeaderRow);
foreach (DataColumn column in all("Users").Columns)
{
TableHeaderCell tHeaderCell = new TableHeaderCell();
tHeaderCell.Text = column.ColumnName;
tHeaderRow.Cells.Add(tHeaderCell);
}
TableHeaderCell tShowHeaderCell = new TableHeaderCell();
tHeaderRow.Cells.Add(tShowHeaderCell);
string id = "";
int i = 0;
foreach (DataRow row in all("Users").Rows)
{
TableRow tRow = new TableRow();
tRow.TableSection = TableRowSection.TableBody;
testTable.Rows.Add(tRow);
foreach (DataColumn column in all("Users").Columns)
{
TableCell tCell = new TableCell();
tCell.Text = row[column.ColumnName].ToString();
tRow.Cells.Add(tCell);
if (column.ColumnName == "id")
id = row[column.ColumnName].ToString();
}
LinkButton showlink = new LinkButton();
showlink.Text = "<i class='icon-file'></i>";
showlink.ID = "linkShow" + "_" + i.ToString();
showlink.CssClass = "tip-top";
showlink.CommandArgument = id;
TableCell tShowCell = new TableCell();
tRow.Cells.Add(tShowCell);
tShowCell.Controls.Add(showlink);
showlink.Click += new EventHandler(Show);
i++;
}
}
protected void Show(object sender, EventArgs e)
{
// Do stuff
}
答案 0 :(得分:0)
由于您使用了更新面板,因此它不会回发页面。您需要强制回传页面。或者您应该删除更新面板。