问题:在gridview中建模板列嵌套Image控件用于显示图片.不论我怎么调,前台图片都显示不了,查源代码,发现src="";为空.我试了把图片路径用相对路径,绝对路径都试了,怎么调都不行.请教高手指点.后台代码 
protected void GridView6_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer)
        {
                Image strimage = (Image)e.Row.Cells[2].FindControl("image3");
                strimage.ImageUrl = "http://localhost/oa/image/new5.gif";
           
        }
    }
前台代码:
<asp:GridView ID="GridView6" runat="server" AutoGenerateColumns="False" ShowHeader="False" BorderWidth="0px" Width="100%" OnRowDataBound="GridView4_RowDataBound" BorderStyle="None" OnDataBound="GridView6_DataBound">
                              <RowStyle Height="25px" />
                              <Columns>
                                  <asp:HyperLinkField DataNavigateUrlFields="id" DataNavigateUrlFormatString="videoplay/mediaplayer.aspx?id={0}"
                                      DataTextField="video_title" ShowHeader="False" Target="_blank" />
                                  <asp:BoundField DataField="video_datetime" Visible="False" />
                                  <asp:TemplateField>
                                      <ItemTemplate>
                                          <asp:Image ID="Image3" runat="server"  />
                                      </ItemTemplate>
                                  </asp:TemplateField>
                              </Columns>
                          </asp:GridView>

解决方案 »

  1.   

    OnRowDataBound="GridView4_RowDataBound"
    ====》OnRowDataBound="GridView6_RowDataBound"
      

  2.   

    <img src='<%#Eval("Detailurl") %>' border="0" width="48px" height="66px" /> 直接绑定数据库字段得了
      

  3.   

    <img src=' <%#Eval("Detailurl") %>' border="0" width="48px" height="66px" /> 直接绑定数据库字段得了
    GOOD
      

  4.   

    试试:
    strimage.ImageUrl = "~/oa/image/new5.gif"; 
      

  5.   

    我觉得楼主的做法有点麻烦,你可以那样做,  你在后台指定数据源,然后执行绑定方法在页面上把需要 显示图片的列转成模板列,然后直接    image 标签的  src=<%Eval("ImageSrc")%>  ,
    这样会省去很多麻烦。。