Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

how do you reference a buttonTempleteColumn in a datagrid ?

Hi I'm trying to find out how you reference the button that's been clicked in a datagrid's buttonTempleteColumn ?
[128 byte] By [Matrix.net] at [2007-11-11 9:57:03]
# 1 Re: how do you reference a buttonTempleteColumn in a datagrid ?
http://forums.dev-archive.com/showthread.php?t=157523
Phil Weber at 2007-11-11 23:12:13 >
# 2 Re: how do you reference a buttonTempleteColumn in a datagrid ?
by Captions you mean the Text property of the button correct? I've never used Cases . So basically an example of what I would do would be :

If TypeOf e.CommandSource Is Button Then
Dim btnSource As Button = DirectCast(e.CommandSource, Button)
Select Case btnSource.Text
Case "Button1"
code here for this case

Case "Button2"
code here for this other case

End Select
End If

correct ?
Matrix.net at 2007-11-11 23:13:13 >
# 3 Re: how do you reference a buttonTempleteColumn in a datagrid ?
Correct. If you simply need a reference to the button that fired the event, then you only need this line:

Dim btnSource As Button = DirectCast(e.CommandSource, Button)
' Now use btnSource as you would any other button
Phil Weber at 2007-11-11 23:14:17 >
# 4 Re: how do you reference a buttonTempleteColumn in a datagrid ?
thanks Phil
Matrix.net at 2007-11-11 23:15:22 >
# 5 Re: how do you reference a buttonTempleteColumn in a datagrid ?
Only problem I'm having now though is that the code that needs to execute in either case needs to know what the selected row is and so I'm getting objects not set to an instance error messages when I click them . I suppose somehow I need to execute the SELECT command in the code for both cases but dont know how.

OR

Maybe I dont have to know what is selected, I just need to know the rowIndex that the button lies on. Again I dont know how you would do that.
Matrix.net at 2007-11-11 23:16:16 >