I am generating dynamic table (testtable
) and simultaneously I am generating LinkButton
in last column of each row which doesn't get fired when I click on it. all("Users")
returns DataTable
. Please Help.
Markup
<asp:UpdatePanel ID="MainUpdatePanel" runat="server" Visible="false">
<ContentTemplate>
<asp:Table ID="testTable" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Code
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
}
Because of you have use update panel that's why it will not post-back the page. You need to post-back the page forcefully. or You should have to remove update panel .