How to Call javascript function by clicking on Gridview link button
-
Dear friends, I have a linkbutton in gridview. When I click on that linkbutton, I need to get some data based on the row which I clicked and this data to be sent to a javascript function. Please help me how to achieve this. It's very urgent. Regards, Cheguri.
-
Dear friends, I have a linkbutton in gridview. When I click on that linkbutton, I need to get some data based on the row which I clicked and this data to be sent to a javascript function. Please help me how to achieve this. It's very urgent. Regards, Cheguri.
-
For that you need to use "ItemTemplate" column for your Link Button and write according to following code.
You just need to use LinkButton instead of button. HTH
Jinal Desai - LIVE Experience is mother of sage....
This isn't going to help with calling a funciton dependent upon the underlying data row.... Assuming you want to create a specific Javascript call for each row, dependent on (say) the row ID of the underlying dataview, you would do better to use a ButtonColumn: <asp:ButtonColumn ButtonType="LinkButton" CommandName="doesnt_matter" Text="whatever" /> and add your JavaScript fucntion in the page's head: function fname(r) { alert('You clicked row with ID# ' + r); } and bind this in the ItemDataBound event: If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim dr As DataRow = e.Item.DataItem.Row Dim js As String Dim btn As LinkButton = e.Item.Cells(X).Controls(0) ' replace "X" by the appropriate column index js = "fname(" & CStr(dr("ID")) & ")"; return false;" btn.Attributes.Add("onclick", js) End If NB the extra "return false" statement - this prevents the link-button from posting the entire form back to the server. btw, OP: re "It's very urgent." Please don't put this sort of thing in your posts. That is no-one's problem but yours.