Amigos,
Estou criando de forma dinâmica uma Table. Na primeira coluna estou criando 2 botões de forma dinâmica diretamente pelo C# e preciso atribuir o evento do click a estes botões, mas ao incluir este evento o botão não executa a função.
Será que alguém pode me ajudar? Segue o código fonte:
private string CarregaTable()
{
SqlConnection conn = new SqlConnection(@"Data Source=LOCALHOST;Initial Catalog=TESTE_WEB;User ID=sa;Password=vls021130");
Pais clPais = new Pais();
DataSet ds = new DataSet();
ds = clPais.Consultar(conn);
StringBuilder sb = new StringBuilder();
int i = 0;
if (ds != null)
{
while (i <= ds.Tables[0].Rows.Count - 1)
{
sb.AppendLine("<tr>");
sb.AppendLine(" <td> <Button ID=" + @"""" + "BtExc_" + ds.Tables[0].Rows[i]["Sigla_Pais"].ToString() + @""""
+ " runat=" + @"""" + "server" + @"""" + " OnClick=" + @"""" + "Button1_Click" + @"""" + "/>"
+ "<i class=" + @"""" + "glyphicon glyphicon-trash" + @"""" + "></i>");
sb.AppendLine(" <Button ID=" + @"""" + "BtAlt_" + ds.Tables[0].Rows[i]["Sigla_Pais"].ToString()
+ @"""" + " runat=" + @"""" + "server" + @"""" + " OnClick=" + @"""" + "Button1_Click" + @""""
+ "/>" + "<i class=" + @"""" + "glyphicon glyphicon-pencil" + @"""" + "></i> </td>");
sb.AppendLine(" <td>" + ds.Tables[0].Rows[i]["Sigla_Pais"].ToString() + "</td>");
sb.AppendLine(" <td>" + ds.Tables[0].Rows[i]["Nome_Pais"].ToString() + "</td>");
sb.AppendLine(" <td>" + ds.Tables[0].Rows[i]["Cod_IBGE_Pais"].ToString() + "</td>");
sb.AppendLine("</tr>");
i++;
}
}
return sb.ToString();
}
protected void Button_Click(object sender, EventArgs e)
{
Button clickedButton = (Button)sender;
Response.Write("<script>alert('" + clickedButton.ID.ToString() + "');</script>");
}