I have dynamically created a column within a gridview for a button to appear in each row. And am trying to get an onclick event to work.
ButtonField test = new ButtonField();
test.Text = "Details";
test.ButtonType = ButtonType.Button;
test.CommandName = "test";
GridView1.Columns.Add(test);
My asp basic as everything is dynamically added to the gridview:
<asp:GridView ID="GridView1" runat="server"> </asp:GridView>
This appends the button(s) fine however I can't seem to find a parameter to add an on-click event on the test button field.
I've tried:
void viewDetails_Command(Object sender, GridViewRowEventArgs e)
{
if (test.CommandName == "test")
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Event works')", true);
}
}
This doesn't run as I assume it's not bound to anything however I cant see where I would bind this event function to? Just using an alert message to test the onclick works!
Any help would be great!