Solved

How to pass gridview button commandargument to jquery dialog

Posted on 2014-04-09
4
3,357 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now