Solved

How to pass gridview button commandargument to jquery dialog

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
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…
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.
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…

752 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