Bunch's Blog

  Home  |   Contact  |   Syndication    |   Login
  48 Posts | 0 Stories | 36 Comments | 0 Trackbacks

News

Tag Cloud


Archives

Green

This is a similar technique to the one outlined in this post. The idea is simple, you have a data value that you want to pass to a Javascript function through a button click on a GridView row. The example below shows how to pass a variable, in this case OtherID, to a Javascript function that opens a new modal window which holds a different aspx page.

function ShowOther(OtherID)
        {
           window.showModalDialog('OtherPage.aspx?OtherID=' + OtherID, 'dialogHeight:600px;dialogWidth:600px;')
        }

In the GridView create a TemplateField and place a button inside the ItemTemplate that will trigger the Javascript function.

<asp:TemplateField HeaderStyle-Width="10%" HeaderText="Info">
   <ItemTemplate>
      <asp:Button ID="btnOther" runat="server" Text="Edit" OnClientClick='<%# EVAL("OtherID", "return ShowOther({0})") %>'/>
   </ItemTemplate>
</asp:TemplateField>

The trick lies in evaluating the OtherID and putting the Javascript call togther in OnClientClick.

Technorati Tags: ,,
posted on Monday, June 08, 2009 7:33 AM

Feedback

# re: Passing a GridView value to Javascript 8/6/2009 9:57 AM biff rockwell
You rock. I have a master detail Gridview I have played with (in my spare time) and this is a VERY easy, nice, simple solution.

Two thumbs up!

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: