0

I have control that inherited from ITemplate Interface. Data is displayed in HtmlTable control, that automatically generated on control initialization. Each row contain ImageButton controls that represent standard command (Edit, Delete, etc). Here code for creating ImageButton with standard command and adding it to row template:

var lkbCancel = new ImageButton()
{
    CommandName = "Edit",
    ImageUrl = "EditIco.png",
    ToolTip = "Edit",
    CausesValidation = false,
};

commandCell.Controls.Add(lkbCancel);

I would like to add ImageButton with custom command (not standard commands Add, Edit, Delete and other). So, how to add custom command and handle it correctly in Itemplate control?

digor_ua
  • 572
  • 2
  • 7
  • 20

1 Answers1

1

Just subscribe to the click event ?

lkbCancel.Click += (sender,e) => {
    //Do something here..
};

You can get access to the current data item that is bound to the row, see here

Richard Friend
  • 15,800
  • 1
  • 42
  • 60
  • But I cannot access to underplaying row in Click event implementation... May be is exists some way to pass current row in Click or Command events? – digor_ua Jan 03 '12 at 10:38
  • How do you currently handle the `Edit` and `Delete` commands ? – Richard Friend Jan 03 '12 at 10:42
  • You probably could get access to the table row as you are in the control tree using `NamingContainer` or `Parent`, however you can access the data item the row is bound to, see http://msdn.microsoft.com/en-us/library/y0h809ak(v=vs.71).aspx – Richard Friend Jan 03 '12 at 10:51
  • I don't handle `Edit` and `Delete` commands. This is standard comaands and automatically handled in bindable objects. I just specify "Edit" or "Delete" in `CommandName` property and command will works as expected without any additional actions. – digor_ua Jan 03 '12 at 10:53