If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Datagrid column events

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-09, 22:22
Access Junkie Access Junkie is offline
Registered User
 
Join Date: Jun 2006
Posts: 72
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.
Reply With Quote
  #2 (permalink)  
Old 10-16-09, 02:04
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,596
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.
Reply With Quote
  #3 (permalink)  
Old 10-16-09, 13:35
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,071
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? ***
Reply With Quote
  #4 (permalink)  
Old 10-19-09, 23:11
Access Junkie Access Junkie is offline
Registered User
 
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 .
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On