Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Grid view with Ajax button extender, return row clicked

Posted on 2011-09-20
9
Medium Priority
?
538 Views
Last Modified: 2012-05-12
Hi Experts

I have a grid view control with an ajax toolkit confirm button extender, the code works fine but I want to store the selected row number from the data grid. As soon as the ajax confirm button appears the e value is set to the ajax control. Any ideas?
<asp:TemplateField HeaderText="Delete"  InsertVisible="False" Visible="False">
                         <HeaderStyle BackColor="#1973BB" ForeColor="White" HorizontalAlign="Center" />   
                        <ItemTemplate>
                           <asp:ImageButton ID="BookDelete" runat="server"
                                CausesValidation="False" 
                                ImageUrl="~/Images/icon-delete.jpg" OnClick="Button1_Click" />

                           <ajaxToolkit:ConfirmButtonExtender ID="ConfirmBookDelete" 
                    runat="server" TargetControlID="BookDelete"
                    ConfirmText="test"/>
                      </ItemTemplate>

Open in new window

0
Comment
Question by:MrDavidThorn
[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
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:BlueYonder
ID: 36567238
To get a value from the row use the a hiddenfield
<asp:HiddenField runat="server" ID="hfId" Value='<%# Bind("Id") %>' />

to retrieve the value in code behind call hfId.value
0
 
LVL 9

Expert Comment

by:BlueYonder
ID: 36567251
The row number can be obtained from e.Row.RowIndex.  The eventargs is GridViewRowEventArgs
0
 

Author Comment

by:MrDavidThorn
ID: 36567333
sorry I dont quite understand, I have the Button1_Click routine  which is fired when the button is clicked, the ajax pop appears before the routine is executed if I use the  e value in Button1_Click  it returns the value from the ajax message box
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        
    End Sub

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:BlueYonder
ID: 36567365
Protected Sub Button1_Click (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
Button1.Click
        e.Row.RowIndex;//this is the row number
    End Sub
0
 
LVL 9

Expert Comment

by:BlueYonder
ID: 36567372
The event argument used is System.Web.UI.WebControls.GridViewRowEventArgs which contains the row number.  If you use just System.EventArgs, it will not contain the row number.
0
 

Author Comment

by:MrDavidThorn
ID: 36567415
I get the error message

Method 'Protected Sub Button1_Click (sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs)' does not have a signature compatible with delegate 'Delegate Sub ImageClickEventHandler(sender As Object, e As System.Web.UI.ImageClickEventArgs)'.      

your code would work fine if I eant using the Ajax confirm button extender
0
 
LVL 9

Accepted Solution

by:
BlueYonder earned 2000 total points
ID: 36567444
1. Add this your GridView:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
            DataSourceID="SqlDataSource1" OnRowCreated="GridView1_RowCreated1" >

  <Columns>
            <asp:TemplateField HeaderText="myRowid">
            <ItemTemplate><asp:Label runat="server" />                    
            </ItemTemplate>          
            </asp:TemplateField>

...

</Columns>

2. Add this to your code page

  Protected Sub GridView1_RowCreated1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
        If e.Row.RowType = DataControlRowType.DataRow Then

            ' Retrieve the Label from the first column.
            Dim myLabel As Label = CType(e.Row.Cells(0).Controls(0), Label)

            ' Set Label text equal to the rowIndex +1
            myLabel.Text = e.Row.RowIndex.ToString() + 1

        End If
    End Sub
0
 

Author Comment

by:MrDavidThorn
ID: 36568154
the above method doesnt work
A) its on the OnRowCreated
B) I get the error message when using e.row.rownumber()

       'System.Web.UI.WebControls.GridViewCommandEventArgs.Friend ReadOnly Property Row As System.Web.UI.WebControls.GridViewRow' is not accessible in this context because it is 'Friend'.      

It works when I use debug mode but when I start the app it complains

Im new to Ajax so im obviously missing a trick!
0
 

Author Comment

by:MrDavidThorn
ID: 36568569
After much searching I found the answer the imagebutton needs the select command name
     <asp:ImageButton ID="BookDelete" runat="server"
                                CausesValidation="False" CommandName="Select"
                                ImageUrl="~/Images/icon-delete.jpg" />


and then in my vb.net code Iv used
    Response.Write(gvBookNumber.Rows(gvBookNumber.SelectedIndex).Cells.Item(0).Text)

Many thanks!
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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

688 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