GridView中的ImageButton [英] ImageButton in a GridView

查看:88
本文介绍了GridView中的ImageButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview第四列的项目模板中有一个ImageButton.我正在尝试在* .aspx.cs文件中访问它,但无法这样做.我需要此按钮将其作为参数传递给方法,并尝试了包括该路由在内的多种路由,这些路由似乎应该起作用:-

(ImageButton)Gridview.FindControl("EditButton");

"EditButton"是ImageButton的名称.

有人可以帮帮我吗.
谢谢,
Sudeep

I have an ImageButton in the Item Template of the fourth column of a gridview. I am trying to access it in the *.aspx.cs file but am unable to do so. I need this button to pass it as a parameter to a method and have tried multiple routes including this one which seemed like something that should have worked:-

(ImageButton)Gridview.FindControl("EditButton");

"EditButton" is the name of the ImageButton

Could anyone help me out.
Thanks,
Sudeep

推荐答案

在调用如下方法时:(ImageButton)Gridview.FindControl("EditButton");您需要告诉它从哪一行获取控件.因此它应该看起来像这样:
(ImageButton)Gridview.Rows[0].FindControl("EditButton");

数字(0)是行的索引.或者,您也可以在ImageButtons onClick方法中获取它.在这种情况下,发送者参数(作为对象出现)是ImageButton.
When calling a method such as this: (ImageButton)Gridview.FindControl("EditButton"); you need to tell it which row to get the control from. So it should look like this:
(ImageButton)Gridview.Rows[0].FindControl("EditButton");

The number (0) is the index of the row.

Alternatively you can get it in the ImageButtons onClick method. In this case, the sender parameter (comes in as an object) is the ImageButton.


这篇关于GridView中的ImageButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆