asp.net gridview控件 [英] asp.net gridview control
本文介绍了asp.net gridview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
如何在网格视图行数据绑定事件中找到图像控件
推荐答案
请查看Control.FindControl
方法。 此处 [ ^ ]是MSDN链接。
一个示例用法是:
Please look at theControl.FindControl
Method. Here[^] is the MSDN link.
An example usage will be:
Label myLabel = (Label)myGridView.Rows[myGridView.SelectedIndex].Cells[2].FindControl("myLabel");
祝你好运,
OI
Good luck,
OI
试试这个
Try this
protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
(Image) img=((Image)e.Row.FindControl("Image control id"));
}
}
例如你有Gridview1有3列picturid,picturname,picture。
E.g. you have Gridview1 with 3 columns picturid,picturname,picture.
<asp:templatefield xmlns:asp="#unknown">
<itemtemplate>/*3rd column of gridview*/
<asp:image id="Image1" imageurl="~/images/ab.jpg" runat="server" />
</itemtemplate>
</asp:templatefield>
gridview的RowDataBound事件:
RowDataBound event of your gridview:
protected Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image desired_image = (Image)e.Row.Cells[2].FindControl("Image1 ");
}
}
这篇关于asp.net gridview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文