link button

L

Lerp

Hi all,

How would I go about creating a link button inside my datagrid that calls a
sub on the same page when clicked....this button will have an image instead
of textual link ie: I don't want a regular <asp:button> tag to do this.


Cheers and thanks, Lerp
 
C

Curt_C [MVP]

use the asp:ButtonColumn with the Text="<img...>"
They give it a CommandName
Initialize the grids ItemCommand and you should be good to go.

like this....

<asp:DataGrid........ItemCommand="myItemCommand" >
<....>
<asp:ButtonColumn..... CommandName="myCommand"..../>

Then in the codebehind
Private void InitializeComponent()
{
this.myGrid.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.myItemCommand);
}
private void myItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName == "myCommand")
{
....do your sub here
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top