Referencing ATTRIBUTES property of a datagrid commandbutton

I am trying to open a new child window and pass parameters back and forth. I understand that in order to accomplish this from a button, the following code could be used to call a custom javascript procedure that opens the new window:

      Button1.Attributes("onclick") = "javascript:OpenDialog()"

Now for my problem. How do I set the ATTRIBUTES property for a command button within a datagrid? I created a datagrid, added a template column and attached a commandbutton to it, named the commandbutton uniquely, and can't seem to figure out how to reference it (I'm a novice with using datagrid template columns, and ASP.NET in general). Here was the line of code I was playing with (it obviously doesn't work):

      dg.Columns(0).cmdSelect.Attributes("onclick") = "javascript:OpenDialog()"

If you need more info, please reply. Thanks in advance for any assistance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hey BigFoot,

You cannot access the button directly. At run-time you should use DataGrid's ItemDatabound event and place there code like this (writing from directly, not pasting from a working code, so syntax errors may ocure):

If e.Item.ItemType = ListItemType.Item Or _
             e.Item.ItemType = ListItemType.AlternatingItem Then
   Dim sCmd as System.Web.UI.WebControls.Button
   sCmd=CType(e.Item.Cells(0).FindControl("cmdSelect"), System.Web.UI.WebControls.Button)
   sCmd.Attributes("onclick") = "javascript:OpenDialog()"
End if

This code assumes that button, named "cmdSelect" is put in the first (0) column of the datagrid and this column is a template column.

Hope this helps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
big1975footAuthor Commented:
Hey Ramunickas, It works great! Thanks for your assistance.
Very pleased to hear that :)

Good luck!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.