Click here to Skip to main content
15,036,363 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i got issues for row databound in gridview controll?i add attributes for imagebutton(add) in gridview .ADD button correctly response, but other imagebutton like Edit,DEl also response same function! it is my problem!
If e.Row.RowType = DataControlRowType.DataRow Then
                Dim ADD_img As String = DirectCast(e.Row.FindControl("Add"), ImageButton).CommandName.ToString
 Dim del As String = DirectCast(e.Row.FindControl("imgdel"),ImageButton).CommandName.ToString
If Not Add_img Is Nothing Then
   Add_img = Add_img & "." & Session.Item("ID")
     e.Row.Attributes.Add("OnClick", "javascript:return openph(" & Edid_img & ")")           
end if     

                    If Not Del_img = "" is nothing Then

                End If

You're adding the javascript to the entire Row, not to the single ImageButton.

So, I think, the javascript function will trigger for every button and link in the entire row.
Try to cast ADD_img to a ImageButton (and not to a String). Then
ADD_img.Attributes.Add("OnClick", "javascript:return openph(" & Edid_img & ")")

Sorry, I code in C# but should be the same.
Let me know!
If e.Row.RowType = DataControlRowType.DataRow Then
                Dim ADD_img As imagebutton = DirectCast(e.Row.FindControl("Add"), ImageButton)
 dim result as string

  result= Add_img.commandname.tostring & "." & Session.Item("ID")
    Add_img.attributes.Add("OnClick", "javascript:return openph(" & result & ")")           
end if     
                End If

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900