Gridview code will not work... please help

  • Thread starter Thread starter Nick
  • Start date Start date
N

Nick

Hi,

Can anyone take a look at the code below and suggest why it may not be
working

---------------------------------
Dim test As ImageButton
test = CType(e.Row.Cells(1).FindControl("ButtonField"), ImageButton)
test.ImageUrl = "~/status_failed.gif"
---------------------------------


I'm doing this when DataBound for the Gridview section.

I get, Object not set to an instance of an object.


So it looks like it can't find the object? I've tried changing the code so
many times and it fails to work.

I've spent weeks on this code. any idea's?


Cheers,

Nick
 
Hi Darren,

Still dosen't seem to work, their is no e.item for some reason. I only have
e.row ?

Cheers,

Nick
 
My bad, i was thinking datagrid for some reason. Use the code you
originally had, but call it for the RowDataBound event, rather than the
DataBound event.

-Darren Kopp
http://blog.secudocs.com/
 
Hi Darren,

Thanks for all your help.. but I still can't get this working.

I have tried:

Dim myControl1 As Control = FindControl("ImageButton")
If (Not myControl1 Is Nothing) Then
' Get control's parent.
Dim myControl2 As Control = myControl1.Parent
Response.Write("Parent of the text box is : " & myControl2.ID)
Else
Response.Write("Control not found.....")
End If

Just to see if it actually locates the control and it still won't work.

Any idea's?

Cheers,

Nick
 
ah,

I have fixed it!!

Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles GridView1.Load
Dim rowCollection As GridViewRowCollection = GridView1.Rows
For Each gridRow As GridViewRow In rowCollection
Dim rowCell As TableCellCollection = gridRow.Cells
For Each itemCell As TableCell In rowCell
For Each ctl As Control In itemCell.Controls
If TypeOf ctl Is ImageButton Then
Dim chk As ImageButton = CType(ctl, ImageButton)
chk.ImageUrl = "~/status_failed.gif"
End If
Next
Next
Next
End Sub

Thank you so much for your help Darren. You pointed me in thr right
direction.

Cheers!

Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top