Judy, you can access objects within a gridview control by direct-casting to them in the gridview control methods.
For instance, look at ~/Admin/Orders/Default.aspx.cs. Able uses a Gridview control called "OrderGrid" in the HTML-side and interacts with it in the code-behind.
In the code-behind, they have a function
Code: Select all
protected void OrderGrid_RowCommand(object sender, GridViewCommandEventArgs e)
This method fires whenever a Gridview command button is pressed in the grid. The current row of the button that was pressed is passed as a parameter. Since the current row is passed, you can direct-cast that row or its contents into a new variable that represents the control you want. If you direct-cast it into a Row object, then you can do a findcontrol within that row object to locate the control (by Id like "Image1") you want to manipulate.
The key is remembering that everything in .Net is a "container". Normally you search a "page container" for a control like a textbox or image. But when a gridview is involved, you have remember the container hiearchy has changed and is now "Page->GridView->GridRow".
The gridview control lets you hook into all sorts of functions. So you can do your stuff when the gridview loads a row, displays a row, refreshes a row, when a command button is pressed etc.
Now, to extend it further for a sec. Let's say you have a gridview on the ac_Products table. But you want the product Thumbnail image to be in the gridview instead of the actual thumbnail image URL. That becomes very easy - on the HTML side just make one of the columns:
Code: Select all
<ASP:Image runat="server" Imageurl="<% EVAL("ImageUrl") %>"></Image>
So you don't even have to call any functions or anything. You just tell the gridview to "substitute" the ac_products.ImageUrl value into the parameter for the Image control. Normally you do this in a gridview template field so it's easier to control layout.
~/Admin/Orders/Default.aspx and .aspx.cs has some great examples of working with gridview controls, methods, template fields and even calculated fields.
If you want to use RecursiveFindControl(), you have to pass it the container object. In your case, it would be the page. But given the example you provided, you shouldn't have to do it. In your example code, you would just reference it as Image1.ImageUrl = "~/Mypic.jpg" or Image1.Width=200 etc.