Referencing ATTRIBUTES property of a datagrid commandbutton

Posted on 2005-05-09
Medium Priority
Last Modified: 2008-03-06
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.
Question by:big1975foot
  • 2
LVL 14

Accepted Solution

Ramuncikas earned 500 total points
ID: 13961879
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

Author Comment

ID: 13962153
Hey Ramunickas, It works great! Thanks for your assistance.
LVL 14

Expert Comment

ID: 13962255
Very pleased to hear that :)

Good luck!

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question