-
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 ?
-
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!
-
 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.
-
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!
-
 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.
-
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.
-
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!
-
 Originally Posted by Phil Weber
I said TemplateColumn, not ButtonColumn. Please re-read my first reply above.
I tried both
-
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!
-
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.
-
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.
-
never mind figured out what I needed to do , thanks anyways !!!!!!
-
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
-
Replies: 8
Last Post: 04-03-2002, 06:41 PM
-
Replies: 150
Last Post: 03-04-2002, 05:40 PM
-
By devi in forum VB Classic
Replies: 3
Last Post: 07-09-2001, 03:25 PM
-
By Steven Bell in forum .NET
Replies: 260
Last Post: 06-01-2001, 04:32 PM
-
Replies: 1
Last Post: 09-22-2000, 09:11 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks