1

I have a gridview that displays data that I retrieved from a database along with an imageButton Field. How can I get to the eventhandler of the imageButton so that I can add code to redirect the Image to a different we page when I click on it?

<asp:GridView ID="GrdBooksRated" runat="server" AutoGenerateColumns = "False" 
        Font-Names = "Arial" > 
        <Columns> 
            <asp:BoundField DataField ="title" HeaderText ="ID" /> 

            <asp:TemplateField> 
                <ItemTemplate> 
                    <asp:ImageButton ID="ImageButton1" ImageUrl ='<%# Eval("pictureUrl")%>' runat="server" /> 
                </ItemTemplate>  
            </asp:TemplateField>  
        </Columns>  
    </asp:GridView>

1 Answer 1

2

If you don't have to pass anything to the handler, you could simply define an OnClick event handler.

<asp:ImageButton ID="ImageButton1" 
  OnClick="ImageButton1_Click" ImageUrl ='<%# Eval("pictureUrl")%>' runat="server" />


  void ImageButton1_Click(object sender, ImageClickEventArgs e) 
  {
     // your code here.
  }

if you do have to pass some bound data, you can use OnCommand method. The msdn post has an example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.