Hi Lars,
You need to catch the button click in the Datagrid's ItemCommand event.
After that, you use the DataGridCommandEventArgs to find out which control
caused the event. If it was the button (as evidenced by the CommandName),
you can call your custom DoTask(), perhaps passing it information about the
row or other values.
There's some code at the bottom of this page that should give you the idea:
http://msdn.microsoft.com/library/de...webcontrol.asp
// C#
private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// e.Item is the row of the table where the button was
// clicked.
string productID = e.Item.Cells[2].Text;
if (e.CommandName == "AddToCart")
{
// Add code here to add the productID item to the cart.
}
DataGrid1.DataBind();
}
"Lars Pedersen" <lsp*_AT_*oncable.dk> wrote in message
news:...
> Hi!
>
> In a datagrid, where I'm building all my columns in codebehind, I have a
> ButtonColumn.
> When user clicks the button, I want to call a function.
> I have tried the CommandName property, but it wont fire.
>
> Example:
>
> ButtonColumn bcol = new ButtonColumn();
> bcol.ButtonType = ButtonColumnType.LinkButton;
> bcol.HeaderText = "Kurv";
> bcol.DataTextField = "ID";
> dgProductList.Columns.Add(bcol);
>
> private void DoTask()
> {
> ...Some code
> }
>
> Question:
> How do I call DoTask(), when clicking the ButtonColums button.
>
> A syntax example would be very helpful to me.
> Thanks..
>
>