Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to pass gridview button commandargument to jquery dialog

Posted on 2014-04-09
4
Medium Priority
?
3,716 Views
Last Modified: 2014-04-10
In an asp.net 3.5 website I have a gridview with an imagebutton on each row. The imagebutton onclick opens a jquery dialog.

How can I pass the imagebutton commandargument to the jquery dialog to be stored there in a hidden field?

Any help would be much appreciated.

Basic code is as follows:

<asp:GridView ID="dgMap" runat="server" AllowSorting="True" AutoGenerateColumns="False"........................

  <asp:TemplateField>
            <ItemTemplate>
                <asp:ImageButton ID="imgbtnViewDialog" runat="server"  ImageAlign="Middle" ImageUrl="~/images/copy.gif" CommandArgument="<%# Container.DataItemIndex %>"
    CssClass="imgbtnViewDialogClass" />
            </ItemTemplate>
        </asp:TemplateField>

...............</asp:GridView>

'CSS to open jquery dialog:

    $('.imgbtnViewDialogClass').click(function () {
              $('#dialog-form').dialog('open');
              return false;
          });
0
Comment
Question by:Al230762
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
jayakrishnabh earned 2000 total points
ID: 39991149
you can set alternate text to the image button and access it in its click function.

<asp:ImageButton ID="imgbtnViewDialog" AlternateText='<%# Eval("DataItemIndex") %>' runat="server"  ImageAlign="Middle" ImageUrl="~/Images/bullet.png" CommandArgument="<%# Container.DataItemIndex %>"
                            CssClass="imgbtnViewDialogClass" />

$(document).ready(function(){
            $('.imgbtnViewDialogClass').click(function () {
                var commandargument = $(this).attr('alt');
                //Do anything with commandargument val
                $('#dialog-form').dialog('open');
                return false;
            });
        });
0
 

Author Closing Comment

by:Al230762
ID: 39991160
Excellent answer jayakrishnabh. Thank you so much. I had forgotten about the AlternateText property. I just had to change the AlternateText value to a an item in the DataRow thus:

AlternateText='<%# Eval("eventID")%>'

Thanks again.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39991304
However you may want to use .prop rather than attr OR consider using the
data-xxxx notation and then .data("xxxx") to get it
0
 

Author Comment

by:Al230762
ID: 39991478
Thank you mplungjan. That is useful additional information.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses

782 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