Help on ImageButton ??

G

Guest

Dear all,

I gave a datagrid object wich has a template column define as follow :

<asp:TemplateColumn HeaderText="Evt">
<ItemTemplate>
<asp:ImageButton id="ImageButton2" ImageAlign=Middle runat="server"
ImageUrl="event.gif" CommandName="ShowEvent" CommandArgument
='<%#DataBinder.Eval(Container,"DataItem.ID")%>' >
</asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>

When I click on my imagebutton I would like to trig the Command event of the
image button ?

How can I do that because phisycally the imagebutton is not seen in code as
it belongs to template

Or may be it is not working with it ?

Thnaks for your help
regards
serge
 
M

Matt Dinovo

In a similar scenario I explicitly set the server click event (see below):

<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton Runat="server" Text="Submit"
OnClick="SubmitProfile_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>

Then in the code I redirected the click event back to the ItemCommand event
for the grid:

Protected Sub SubmitProfile_Click(ByVal sender As Object, ByVal e As
EventArgs)
Dim btn As LinkButton = CType(sender, LinkButton)

'NOTE: I set the CommandName of the LinkButton to the ItemIndex for
where it exists in the ItemDataBound event for the grid
Me.myGrid_ItemCommand(Me, _
New
DataGridCommandEventArgs(myGrid.Items(Convert.ToInt32(btn.CommandName)), _
myGrid, _
New CommandEventArgs("Select", Nothing)))
End Sub

HTH,

Matt Dinovo
 

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

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top