Solved

How to pass gridview button commandargument to jquery dialog

Posted on 2014-04-09
4
3,321 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you mplungjan. That is useful additional information.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

743 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

15 Experts available now in Live!

Get 1:1 Help Now