Solved

How to pass gridview button commandargument to jquery dialog

Posted on 2014-04-09
4
3,574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
jayakrishnabh earned 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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.

627 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