Solved

Setting image dynamically in gridview. Findcontrol problem

Posted on 2006-11-09
5
879 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

623 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