Solved

Setting image dynamically in gridview. Findcontrol problem

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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