DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259

    how do you code a buttonColumn ?

    Okay Ive been looking all over the net and still cant find what Im looking for. Im trying to code the button columns on my datagrid so that they do more than just SELECT,UPDATE,and DELETE. Anyone know ?

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Instead of a ButtonColumn, use a TemplateColumn with a button control in it. Then handle the button's server-side OnClick event as you would any other button.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259
    Quote Originally Posted by Phil Weber
    Instead of a ButtonColumn, use a TemplateColumn with a button control in it. Then handle the button's server-side OnClick event as you would any other button.
    well with any other button I would double click it in design mode and I would go directly to the Onclick event . With this, when I double click on the templete button column I end up at the datagrid's SelectedIndexChanged event not the button's Onclick Event.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I assume you're using VB? In the code-behind view, select the button name from the dropdown list in the upper-left of the code window, then select the OnClick event from the dropdown list in the upper-right.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259
    Quote Originally Posted by Phil Weber
    I assume you're using VB? In the code-behind view, select the button name from the dropdown list in the upper-left of the code window, then select the OnClick event from the dropdown list in the upper-right.
    the button in the buttoncolumn of the datagrid is not listed on there. When you look at the menu with the controls , only the datagrid is listed and when you choose the datagrid to view its commands , only the update,delete etc. type commands are listed.

    Do you mean just code those listed events how I see fit ? Or did you mean that I should be able to see the button_click event on there ? Thanks Phil
    Last edited by Matrix.net; 11-29-2006 at 09:33 AM.

  6. #6
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259
    Here's what I'm currently trying to do, I've made a buttoncolumn that has the command name DELETE , I'm entering code inside that event that doesn't do any deleting at all and it looks like you can because I'm able to change a label's text property through clicking on the button.

    However, the key thing that has to happen is that I have to have the buttoncolumn select the row the button is on and then execute some other code that needs to know what the currently selected row is . Can I call the SELECT command ?

    I cannot use a SELECT buttoncolumn because the SELECT command name isnt listed , only the selected index changed event is there and I cant place code in there that can differentiate which buttoncolumn/button was clicked on since I have to have 2 buttoncolumns or can I ?
    Last edited by Matrix.net; 11-29-2006 at 09:45 AM.

  7. #7
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I said TemplateColumn, not ButtonColumn. Please re-read my first reply above.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  8. #8
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259
    Quote Originally Posted by Phil Weber
    I said TemplateColumn, not ButtonColumn. Please re-read my first reply above.

    I tried both

  9. #9
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I also repied to your other thread about how to tell which of two SELECT buttons was clicked: http://forums.devx.com/showthread.php?t=157523 . Did you try that solution?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  10. #10
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259
    Nevermind Phil , thanks though . I believe I just figured it out, first make the buttoncolumn be of type SELECT or whatever type you want (this case its SELECT), convert it to a templete column . THen in the code-behind file make up a public function or sub that executes some code . THen in the HTML view go over to the button in the datagrid code and add the OnClick method and type something like ; Onclick="name of the function or sub"


    the button's events werent listed in the code behind file like you said up top but this works just perfect ! thanks anyways cause atleast you gave me clues on what to look for.

  11. #11
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259
    I'm back again lol , after lunch I tried out the real code I want executed at the function :

    Label1.Text = "testing application button"
    Dim ssn As Integer

    ssn = DataGrid1.SelectedItem.Cells.Item(1).Text
    Dim dset As New DataSet
    Dim accessor As New SqlServerAccessor

    dset = accessor.getApplicationData(ssn)
    If dset.Tables(0).Rows.Count > 0 Then
    Label1.Text = "testing looks good for application button"

    End If

    I'm getting an error message : Object Reference not set to an instance of an object at the line that is Bold. This is the code at the code behind file that executes when you click on the templeteButtonColumn . It seems that the problem has to do with the datagrid1.selecteditem.cells.item(1).text part but dont know why because there are atleast 17 cells going accross .

    Please refer to my post above this one if need to. Thanks

    Also can anyone explain what does a templeteColumn's Onload ,OnUnload,OnCommand, and OnDisposed events do ?
    Last edited by Matrix.net; 11-29-2006 at 02:15 PM.

  12. #12
    Join Date
    Aug 2006
    Location
    PA
    Posts
    259
    never mind figured out what I needed to do , thanks anyways !!!!!!

  13. #13
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    OK, I apologize. I just tried creating a TemplateColumn with a button in it, and you're right, the button doesn't have server-side events like a button outside of a grid would. You can, however, check the e.CommandSource property in the DataGrid's ItemCommand event to determine which button was clicked. Please see my reply in the other thread for more information. (This is why we ask people not to create more than one thread on the same question! ;-)
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. wot is CLR
    By lostguy in forum .NET
    Replies: 8
    Last Post: 04-03-2002, 06:41 PM
  2. .NET equals Efficiency
    By Kevin in forum .NET
    Replies: 150
    Last Post: 03-04-2002, 05:40 PM
  3. Replies: 3
    Last Post: 07-09-2001, 03:25 PM
  4. Another Language
    By Steven Bell in forum .NET
    Replies: 260
    Last Post: 06-01-2001, 04:32 PM
  5. error code in JSP(please chek the code)
    By satish in forum Java
    Replies: 1
    Last Post: 09-22-2000, 09:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links