Dynamically add Template Image Button to GridControl

SteveoAtilla

Well-known member
Joined
Dec 22, 2004
Messages
79
Location
The Frozen Tundra
Hey,

Ive 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, heres 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 cant find "Status" - the button that needs to be updated. For some reason, even though there are controls in the grid, they cant 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 cant find out how to do that. I can add all the bound columns that I need, but the template columns dont 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