Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2006
    Posts
    72

    Unanswered: Datagrid column events

    Hello I am using VS.net 2008

    I have created a page which has a datagrid which is loaded into a placeholder with button columns that are added dynamically during runtime. I cannot however trigger an event when the buttons are clicked.

    Below is a simplified version of the code I am using.

    Code:
    Public WithEvents dgPlanningTable As New System.Web.UI.WebControls.DataGrid()
    
    Private Sub cmdPlanning_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPlanning.Click
        Dim BCSeriesShort As New System.Web.UI.WebControls.ButtonColumn()
        BCSeriesShort.HeaderText = "SeriesShort"
        BCSeriesShort.CommandName = "ItemCommand"
        BCSeriesShort.ButtonType = ButtonColumnType.PushButton
        BCSeriesShort.DataTextField = "SeriesShort"
    
        dgPlanningTable.Columns.Add(BCSeriesShort)
          
        dgPlanningTable.DataSource = sdsPlanningTable
        dgPlanningTable.DataBind()
        PlaceHolder.Controls.Add(dgPlanningTable)
    End Sub
    
    Private Sub dgPlanningTable_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgPlanningTable.ItemCommand
        MsgBox("ItemCommand")
    End Sub
    Obviously I will want it to do more than just say "ItemCommand" but I can't do anything until the event itself is triggered.

    I have tried endless different ways to do this that I have read from endless different pages. Each seems to either deal with a problem slightly different to mine, deal with a different language or have an annoyingly incomplete code snippet that is utterly useless.

    If anyone can suggest anything that might fix this problem, I might be able to stop tearing my hair out.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Just curious, but which machine (server, workstation, other) did you expect to display the message box? Check out http://channel9.msdn.com/forums/Tech...essageboxshow/

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    By you alluding to creating a "page" makes me think you're dealing with ASP.NET (not too mention you're popping UI.WebControls in there...). If that's the case, read Pat's link.

    You also run into the issue in that dynamically created controls do not exist on postback.

    Also also, why datagrid instead of gridview?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Jun 2006
    Posts
    72
    Pat Phelan, I expected to display the message on the workstation machine which at this point in development happens also to be the server machine.

    Teddy, you're right, I am using ASP.NET. I had a bit of a look at the link from Pat (probably less than it deserved.) but I did not really find the solution I was looking for.

    You were correct that the controls I created during runtime were lost on postback. That in fact was the cause of my problem.

    I have since switched to a gridview and started using an empty gridview created in the default.aspx file instead of a placeholder and found that it does not disappear when triggering an event for a control that exists within the gridview. Furthermore the event itself fires allowing me to do what I need to.

    Problem solved .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •