Asp.Net: datagrid event is not fired

Hello experts,
in my Asp.Net (vb.net) web application
I'm using in one web page the following definitions and code:
---
<asp:datagrid id="dgTest" style="Z-INDEX: 103; LEFT: 20px; POSITION: absolute; TOP: 442px"
      runat="server" Width="869px" Height="10px" Font-Size="10pt"
                OnItemCommand="showTestDetails"
      AutoGenerateColumns="False" GridLines="Vertical" HeaderStyle-BackColor="Red" HeaderStyle-ForeColor="White"
      HeaderStyle-Font-Bold="True" HeaderStyle-Font-Name="Verdana" AlternatingItemStyle-BackColor="#dddddd"
      ItemStyle-Font-Name="Verdana" ShowFooter="True"
                DataKeyField="MyKey">

      <FooterStyle Font-Names="Verdana" Font-Bold="True" ForeColor="White" BackColor="Red"></FooterStyle>
      <AlternatingItemStyle BackColor="#DDDDDD"></AlternatingItemStyle>
      <ItemStyle Font-Names="Verdana"></ItemStyle>
      <HeaderStyle Font-Names="Verdana" Font-Bold="True" ForeColor="White" BackColor="Red"></HeaderStyle>

      <Columns>
            <asp:ButtonColumn Text="Close" ButtonType="PushButton" HeaderText="Close"
                                        CommandName="btnClose"></asp:ButtonColumn>
            <asp:BoundColumn DataField="myKey" ReadOnly="True" HeaderText="Key">
                  <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                  <ItemStyle HorizontalAlign="Center" Width="15%"></ItemStyle>
            </asp:BoundColumn>
      </Columns>
</asp:datagrid>

    Private Sub dgTest_ItemCommand(ByVal source As Object, _
              ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgTest.ItemCommand
        Dim itemCell0 As TableCell = e.Item.Cells(0)    ' myKey
        If e.CommandName = "btnClose" Then
            'Me.txtBoxInfo.Text = "You clicked one of the 'Close' buttons!"
        End If
    End Sub

    Sub showTestDetails(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
        Dim itemCell0 As TableCell = e.Item.Cells(0)    ' myKey
        If e.CommandName = "btnClose" Then
            'Me.txtBoxInfo.Text = "You clicked one of the 'Close' buttons!"
        End If
    End Sub
---
Clicking the close button 'btnClose' none of the above's routines receives the control.
Why does this happen?
If anyone knows a solution please supply appropriate [snippet] information.

   Thank you very much!

     HStrix
HStrixAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmarinovCommented:
Hi HStrix,

first of all may be there is a conflict between the 2 subs
try to remove dgTest_ItemCommand and if there is a addhandler
second, are you binding the datagrid within if not ispostback then

Regards!
B..M
0
HStrixAuthor Commented:
Thank mmarinov,
- I changed dgTest_ItemCommand  to XXXdgTest_ItemCommand. => result: no change
- The datagrid is always filled in Page_Load using a subroutine.
0
mmarinovCommented:
HStrix,

if this subroutine is not calling like this

Sub Page_load
    If Not IsPostBack Then
        call the sub
    End If
End Sub

then you will not be able to get the command because when a post back occurs the asp.net modified the state of the datagrid and it does not know that a control was hitted

B..M
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

HStrixAuthor Commented:
The datagrid is filled as follows:

Dim objConn As New OleDbConnection
Dim objAdapter As New System.Data.OleDb.OleDbDataAdapter
Dim objDataset As New DataSet
Dim strSQL As String = "Select * From mytable;"
        objAdapter.SelectCommand = New System.Data.OleDb.OleDbCommand(strSQL, objConn)
        ' Fill the dataset.
        objAdapter.Fill(objDataset)
        ' Create a new view.
        Dim objView As New DataView(objDataset.Tables(0))
        ' Set up the data grid and bind the data.
        dgTest.DataSource = objView
        dgTest.DataBind()

The datagrid is properly filled.
0
HStrixAuthor Commented:
Thank you very much mmarinov,
that was exactly the problem.
It is now working.

    HStrix

   
0
mmarinovCommented:
HStrix,

I'm glad that can help

B..M
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.