This is a migrated thread and some comments may be shown as answers.

Open report link using unique row ID

6 Answers 399 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Craig
Top achievements
Rank 1
Craig asked on 02 Jul 2013, 09:30 PM
Hello,

I have a radgrid to which I recently added a history grid button.

<telerik:GridButtonColumn UniqueName="HistoryColumn" HeaderStyle-Width="18px" ButtonType="ImageButton"
      CommandName="History" Text="Get History" ImageUrl="~\Images\history.png">
</telerik:GridButtonColumn>

And I have a server side method in which I want to capture the id of the respective row of the history button and open a report from a report server that shows the history of the item.

Protected Sub RadGrid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
If e.CommandName = "History" Then
Dim categoryId As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)"UniqueID").ToString
Dim url As String = "link&UniqueID=" & categoryId
End If
End Sub


I have the full URL from another developer and simply want to fire the event to open the URL when the user clicks the history button.  How do I do that?

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Jul 2013, 07:04 AM
Hi Craig,

I guess you want to access the datakey value of the radgrid.
Please try the following code snippet.Set the DataKeyNames property of radgrid in MasterTableView.

ASPX:
<MasterTableView DataKeyNames="Column1">

VB:
If e.CommandName = "History" Then
    Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
    Dim value As String = item.GetDataKeyValue("Column1").ToString()
End If

If this doesn't help,please elaborate your scenario.

Thanks,
Princy
0
Craig
Top achievements
Rank 1
answered on 03 Jul 2013, 05:42 PM
Thank you, Princy.  I understand how to get the id of the selected record.  What I need to do is insert that ID into a URL and open the URL.

I have an existing URL that will use the ID to kick off an SSRS report that opens an Excel spreadsheet.  As I was thinking about it last night, it occured to me that it might be better to use Javascript but if I do it that way, how would I go about passing the row ID to the JS function?
0
Eyup
Telerik team
answered on 05 Jul 2013, 10:27 AM
Hi Craig,

There is no need to post back to the server to achieve the requested functionality. You can use the client click event of the initiator to open the secondary page by using either window.open, navigate, location, etc.

You can also use RadWindow:
http://demos.telerik.com/aspnet-ajax/window/examples/internalcontent/defaultcs.aspx

Hope this helps.
Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Craig
Top achievements
Rank 1
answered on 08 Jul 2013, 02:23 AM
Thank you, Eyup.  I'm not opening another window.  I simply want to fire an event to navigate to a url and I want to insert a value from one of the columns in the chosen row.

Here is the URL that was sent to me.  It's a simple hyperlink:
<a href="javascript:void(window.open('http://<servername>:8080/ReportServer?http%3a%2f%2fourreports2.<domain>.net%2fInternal+Reports%2fStrategic_Planning/History.rdl&rs:Command=Render&rs:Format=Excel&UniqueID=C37C23C6-4FE5-466A-AA0C-893BC6D8634C','_blank'))">Test Link</a>


What I want to do is create an imagebutton that will show at the beginning of every row in my Radgrid that when clicked by the user, will navigate to the report URL above but fill in the unique ID from the ID column of the selected row (bolded part of the URL above).

The Radgrid works great and I have the history column setup with an image button.  Should I call a JS function from the OnClientClick event and build the URL?  Can I use a property of NavigateURL in the image button (doesn't look like it).

The link above simply prompts the user to either open or save an Excel file.  I simply need to know the best way to pass the selected row's unique ID column value to that link.

Thanks!
0
Eyup
Telerik team
answered on 11 Jul 2013, 08:36 AM
Hello Craig,

First, you need to choose the way you will pass the data:
  • Query strings
  • Session state
  • Application state
  • Cookies
Please keep in mind that if you decide to go with client-side approach, you can only use Query strings. You can find detailed information about the suggested options in the following article:
http://msdn.microsoft.com/en-us/library/75x4ha6s%28v=vs.100%29.aspx

Now, you have several possible approaches to choose from in order to achieve the requested functionality:
   
  • Directly set the navigation urls of the links according to your own requirement using query strings. You can check the attached web site to see the different ways of defining link columns.

  • Access the ID of the item container of the clicked link on the server side and build your Query string to redirect to the new page:
           http://msdn.microsoft.com/en-us/library/ms524309%28v=vs.90%29.aspx

  •  Access the ID of the item container of the clicked link on the client side and build your Query string to use navigate or location window functions to redirect to the new page. You can find detailed information about them in various sources over the net.

Hope this helps. Looking forward to your reply when ready.


Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Craig
Top achievements
Rank 1
answered on 15 Jul 2013, 05:14 PM
Thank you, Eyup.  I returned from vacation today and started working on this again.  I ended up getting it to work by looking at your attached solution.

I changed my UniqueID GridBoundColumn to a  GridHyperLinkColumn, assigned an ImageUrl that pointed to my history image, then set the DataNavigateUrlFields property to my uniqueId and set the DataNavigateUrlFormatString property to my long URL with a UniqueId={0} at the end.  It works perfectly.

I appreciate your help and especially appreciate the example you posted.  It helped me greatly.
Tags
Grid
Asked by
Craig
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Craig
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or