Hi,
I have a grid control to which I add a GridButtonColumn. Later, I add an OnClick client event. This part works fine. The image is displayed within each row of the grid and if I click on the image, the javascript function is executed.
Now from within the javascript function, I want to access a value from the grid. The value should come from the row which contains the button which was clicked on. Looking on the internet, I have managed to find out how to get this to work if a row has been selected. The problem is that when you click on a grid button, the row containing the grid button is not necessarily selected e.g. If I first select a row and then click on the button, I can get the value, but if I just click on one of the buttons without first selecting a row, I am aunable to determine the row containing the button. The clicked button itself is inside a specific row so there must be some way to get it.
Below are a few snippets of relevent code. Any help would be greatly appreciated.
Creating the button:
Adding the onclick event to the button
client side javascript event handler. Only works as expected if a row is selected prior to clicking on the button - even though the button itself is inside a specific row.
I have a grid control to which I add a GridButtonColumn. Later, I add an OnClick client event. This part works fine. The image is displayed within each row of the grid and if I click on the image, the javascript function is executed.
Now from within the javascript function, I want to access a value from the grid. The value should come from the row which contains the button which was clicked on. Looking on the internet, I have managed to find out how to get this to work if a row has been selected. The problem is that when you click on a grid button, the row containing the grid button is not necessarily selected e.g. If I first select a row and then click on the button, I can get the value, but if I just click on one of the buttons without first selecting a row, I am aunable to determine the row containing the button. The clicked button itself is inside a specific row so there must be some way to get it.
Below are a few snippets of relevent code. Any help would be greatly appreciated.
Creating the button:
var inchisIncomingEmail = new GridButtonColumn();grid.MasterTableView.Columns.Add(inchisIncomingEmail);
Adding the onclick event to the button
if (e.Item is GridDataItem) { GridDataItem item = (GridDataItem)e.Item; ImageButton btnColumn1 = (ImageButton)item["objhisIncomingEmailID"].Controls[0]; btnColumn1.Attributes.Add("OnClick", "IncomingEmailClick()"); }client side javascript event handler. Only works as expected if a row is selected prior to clicking on the button - even though the button itself is inside a specific row.
function IncomingEmailClick(obj, args) { IncomingEmailOpenWindow('<%=ResolveUrl("~/Modules/Common/HistoryDetail.aspx") %>', obj, null); } function IncomingEmailOpenWindow(url, grid, closeFn) { var gridc = $find("<%=grid.ClientID%>"); var items = gridc.get_masterTableView().get_selectedItems(); if (items.length > 0) { url = url + '?id=' + items[0].getDataKeyValue('objhisID') + '&type=<%=(int)ListType %>' + '&objId=<%=ItemGuid %>'; } var win = radopen(url, null); win.set_modal(true); win.setActive(true); if (closeFn != null) { win.OpenerWindowCloseFn = closeFn; } }