Solved

Setting image dynamically in gridview. Findcontrol problem

Posted on 2006-11-09
5
877 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert Select to DropDownListFor MVC 5 2 47
How to filter by key press ? 6 55
asp.net figure out error 3 23
YouTube API get the Video Tags - vb.net 7 28
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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