Dynamically add Template Image Button to GridControl

SteveoAtilla

Regular
Joined
Dec 22, 2004
Messages
80
Location
The Frozen Tundra
Hey,

I've got a GridControl in an ASP site (VB.NET codebehind), VS 2005.

The user has control over the columns displayed, so the grid needs to be re-built.

As well as that functionality, one of the first two columns (the Image Buttons) needs to be changed based on data in that row (it is the project status, FWIW).

The first time the RowDataBound event fires, everything works fine. After that, any subsequent Bind event errors out.

First, here's the code in the RowDataBound event that fails:

Code:
Dim dt As New DataTable
Dim dv As New DataView
dt = Session("dt")
dv = dt.DefaultView
Dim stat As Integer
Dim ViewProj As ImageButton = CType(e.Row.FindControl("Status"), ImageButton)
stat = CInt(dv.Table.Rows(e.Row.RowIndex).Item(1).ToString)
If stat > 8 Then stat = 0 'no icon available above 8
ViewProj.ImageUrl = "~/Images_2/" + CStr(stat) + ".jpg"
ViewProj.CommandArgument = e.Row.RowIndex.ToString
ViewProj.Visible = True
For x = 0 To count - 1
The error occurs on the stat = CInt command, since FindControl can't find "Status" - the button that needs to be updated. For some reason, even though there are controls in the grid, they can't be found, and we end up with "Object not set to an instance of an object" error.

What I really need to be able to do is to dynamically add a Template column that is an image button, but I can't find out how to do that. I can add all the bound columns that I need, but the template columns don't work.

What the code does is, remove all the columns from 2 to the end, leaving columns 0 and 1 (the template columns). I suspect that this is part of the problem.

Anyway,

HELP!

Thanks.
 
Back
Top