DataGrid Question

J

John McCarthy

Question:

I would like to add a ButtonColumn
to a datagrid on the fly .....

Thus far ....

(1) Adding the button works ....

(2) Trying to hook up an event
handler does not work ....

Conceptually, I must be missing
a big point .... (guessing)

Neither Scott Mitchell nor Waltham,
or Payne, or a whole bunch
of other people - in their books, go into this ...

and perhaps its because
I should not be attempting
to do this .....

i.e. dumb approach ?

My purpose in all this is to
get as much as possible off
the HTML page and onto the
code behind page ...

i.e. the myriad properties
and so on .....

I have googlized this to death
but cannot find an example
of a grid with the same minimal
attributes(?) as below ...

Any help or direction would
be very much appreciated ....

---------------------
HTML Page
---------------------
<ASP:DATAGRID
id="dg1"
runat="server">
</ASP:DATAGRID>

---------------------
Code Behind
---------------------
Some Sub

'--------------------------------
' Add Button Column
'--------------------------------
Dim oBut As New ButtonColumn
oBut.ButtonType = ButtonColumnType.LinkButton
oBut.Text = "Select"
oBut.CommandName = "Select"
dg1.Columns.Add(oBut)

'Nada happens
AddHandler dg1.SelectedIndexChanged, AddressOf my_SelectedIndexChanged

Private Sub my_SelectedIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dg1.SelectedIndexChanged
Dim s as string = "See Spot run ...."
End Sub

Note:
I have no problem adding a normal button to
a page and adding a handler ......

Thanks in advance for any guidence ....

regards,
John McCarthy
 
J

John McCarthy

Joyjit -

thank you for responding to me ......

I put a See Spot run string in the ItemCommand event
and stuck an F9 in it and ran my code .......

when the Grid came up and I clicked on my button
the ItemCommand event was not entered ......

as ALWAYS - theres a real good chance I'm just
not *seeing* things clearly ......

but thats where I am .....

if you can envision this ......

the first column is my Button Column
and there are 3 more Bound Columns that were also
added to the grid on the fly .....

thanks again for taking the time to review this ...

regards,
John McCarthy
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top