开发者

adding code to imagebutton in a grid view

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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜