Solved

Setting image dynamically in gridview. Findcontrol problem

Posted on 2006-11-09
5
873 Views
Last Modified: 2007-12-19
Can someone tell me how to use the findcontrol command when dealing with gridview? I am attempting to set the image url dynamically. The problem I seem to be having is how to set the CONTROLID that is supposed to be used with the  MyCell.FindControl("????").  I am not reading the file from a database, I am simply attempting to set the url to display a certain graphic based on the value of an adjacent cell. I do not know what controlID I need to be looking for. Any help would be greatly appreciated

I have the following code

 <asp:ImageField HeaderText="Graphic" >
           
               
 </asp:ImageField>



 Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound    
   
        If e.Row.RowType = DataControlRowType.DataRow Then

            Dim MyCell As TableCell
            MyCell = e.Row.Cells(6)
            Dim myimage As New Image
            myimage = MyCell.FindControl("????")
            myimage.ImageUrl = "~\0.gif"
0
Comment
Question by:phil301
5 Comments
 
LVL 9

Expert Comment

by:kraffay
ID: 17909274
Try getting a handle to the Image control by its ordinal position in the Cell's control collection:

myimage=MyCell.Controls[0, or whatever index the image control is]
0
 

Author Comment

by:phil301
ID: 17909413
I figured it out. I was using the IMAGEFIELD when I should have been using a TEMPLATEFIELD. By using a TEMPLATEFIELD, it allows you to assign an ID to the control. The above code was correct, just needed the proper ID.

Thanks for your help.
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17909439
Try the following:

Dim MyCell As TableCell
MyCell = e.Row.Cells(6)
for each c as control in MyCell.Controls
  if c.GetType() = TypeOf("Image") Then
    Dim myimage As New Image
    myimage = DirectCast(c,Image)
    Exit For
  end if
Next


--Nauman.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18184062
PAQed with points refunded (125)

Computer101
EE Admin
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now