本文介绍了我怎样才能找到Image控件UnderGridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到图像控件UnderGridview



How can i find Image control UnderGridview

<asp:GridView ID="GridView1" runat="server" Height="65px" Width="477px">
           <Columns>
               <asp:TemplateField>
                   <ItemTemplate>
                       <asp:Image ID="Image7" runat="server" Height="105px" Width="95px" />
                   </ItemTemplate>
               </asp:TemplateField>
           </Columns>
       </asp:GridView>




代码背后的




on code behind

Image imag = ((Image)GridView1.FindControl("Image7"));





调试时显示Imag = null。



it showing Imag = null while debugging.

推荐答案

foreach(GridViewRow row in GridView1.Rows) {
    if(row.RowType == DataControlRowType.DataRow) {
        Image image = row.FindControl("Image7") as Image;
    }
}


protected void rg_ItemDataBound(object sender, GridItemEventArgs e)
        {



{

GridDataItem item =(GridDataItem)e.Item;

Image lblRate =(Image)item.FindControl(lblRate);

这是如果你使用radgrid.You也可以尝试gridview。

}



或试试喜欢这个



foreach(rg.MasterTableView.Items中的GridDataItem项目)

{

RadNumericTextBox txtHoursBilled =( RadNumericTextBox)item.FindControl(txtHoursBilled);

Label lblTotal =(Label)item.FindControl(lbl1);

Label lblRate =(Label)item。 FindControl(lbl2);



}


{
GridDataItem item = (GridDataItem)e.Item;
Image lblRate = (Image)item.FindControl("lblRate");
This is If u r using radgrid.You can also try it for gridview.
}

or try like this

foreach (GridDataItem item in rg.MasterTableView.Items)
{
RadNumericTextBox txtHoursBilled = (RadNumericTextBox)item.FindControl("txtHoursBilled");
Label lblTotal = (Label)item.FindControl("lbl1");
Label lblRate = (Label)item.FindControl("lbl2");

}


这篇关于我怎样才能找到Image控件UnderGridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:58