firedrawndagger
firedrawndagger

Reputation: 3733

Creating a Modal Window on GridView Select in ASP.Net and C#

What's the best way to create a pop-up like modal window that shows upon clicking the Select button in GridView?

   <asp:CommandField ShowSelectButton="true" ButtonType="Button" SelectText="Select Me" />

Also, bonus if you know how to implement this via jQuery.

Upvotes: 1

Views: 5821

Answers (1)

Jim Schubert
Jim Schubert

Reputation: 20367

  • Go into design mode and choose the ticker in the top-right corner of the gridview.
  • Select "Edit Columns" and choose your CommandField.
  • Under the properties (right hand side), select "Convert to TemplateField" and hit OK, and you'll have access to the LinkButton generated by the CommandField.
  • Add a property to the LinkButton for OnClientClick and specify your javascript function in there.

e.g.
<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="openModal();" />

If you don't want the page to postback, openModal() should return false

You can create a modal dialog easily with jQuery UI. The options and some examples are available in the docs: http://docs.jquery.com/UI/Dialog

If you only need something really simple, you can also use the jQuery simple modal plugin available here: http://www.ericmmartin.com/projects/simplemodal/ The examples from this plugin will give you a nice looking confirmation dialog, or any other informational window (even embedded iframes).

Upvotes: 3

Related Questions