DataGrid Question ...

E

Elton Wang

Hi John,

What you missed is you should handle DataGrid ItemCommand
event rather than SelectedIndexChanged event.

Change to following code:

AddHandler dg1.ItemCommand, AddressOf dg1_ItemCommand

And

Private Sub dg1_ItemCommand(ByVal source As Object, ByVal
e As System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles dg1.ItemCommand
If e.CommandName.Equals("Select") Then
Dim s As String = "See Spot run ...."
End If

End Sub

to see what happens.

Hope it is helpful to you.

Elton Wang
(e-mail address removed)
 
E

Elton Wang

Hi John,

I even think you don't need following code to fire event
AddHandler dg1.ItemCommand, AddressOf dg1_ItemCommand
unless you create your datagrid on the fly.

You can still add your button to the datagrid on the fly.
Then you can directly use VS.NET to build a standard
DataGrid_ItemCommand event:
In View Code window from left dropdown list select
datagrid, and in right dropdown list, select ItemCommand
event.

BTW, it is better use reference type of datagrid object in
your
Function Set_ButtonColumn.
It is like this
Function Set_ButtonColumn(ByRef oDG As DataGrid) As Boolean


Regards,

Elton Wang
(e-mail address removed)
-----Original Message-----
Hi Elton

I very much appreciate your response ......
I commented out my code and added the code you suggested.
But I was not able to fire off the ItemCommand event.
This leads me to think I am doing something fundamentally wrong.

What follows is my code and perhaps you will see something that I am
missing. For clarity of reading I present the order in which functions
are called and then after that the code contained in the functions.

'------------------------
'------------------------
If Not Page.IsPostBack Then

Dim i As Integer
Dim iDataSource As Integer
Dim bAutoPostBack As Boolean = True
Dim bAutoGenColumns As Boolean = False

'------------------------
' IGNORE
' Add Fonts to ddlFonts
'------------------------
ddlFonts.DataSource = oclsGrid.Get_ArrayFontFamilyNames
ddlFonts.DataBind()

'------------------------
' IGNORE
' Add Connection to ddlConnection
'------------------------
ddlConnection.DataSource =
oclsGrid.Get_ArrayInteger(1, 9)
 

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,816
Latest member
nipsseyhussle

Latest Threads

Top