Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Asp.Net: datagrid event is not fired

Posted on 2004-10-28
6
Medium Priority
?
577 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:HStrix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 12431422
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
 

Author Comment

by:HStrix
ID: 12431503
Thank mmarinov,
- I changed dgTest_ItemCommand  to XXXdgTest_ItemCommand. => result: no change
- The datagrid is always filled in Page_Load using a subroutine.
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 2000 total points
ID: 12431547
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:HStrix
ID: 12431553
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
 

Author Comment

by:HStrix
ID: 12431590
Thank you very much mmarinov,
that was exactly the problem.
It is now working.

    HStrix

   
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12431610
HStrix,

I'm glad that can help

B..M
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question