Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting image dynamically in gridview. Findcontrol problem

Posted on 2006-11-09
5
Medium Priority
?
882 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

927 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