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

hyperlink column with session variable

5 Answers 226 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TSCGlobal
Top achievements
Rank 1
TSCGlobal asked on 16 Mar 2010, 02:22 PM
I have a project in which one column is a hyperlink column.  Ideally, when the user clicks on the hyperlink, three things happen:

1. The row the hyperlink is in is selected
2. The data in the hyperlink column is passed to a session variable
3. A new browser window opens up, and the session variable is passed to the new page in that separate window.

Currently, it appears that the only thing that is taking place is that a new browser window opens up, in spite of the fact that I have the appropriate code in the SelectedIndexChanged event that would pass the data into the session variable.  I hope someone can help me with this, or perhaps suggest a more efficient way of accomplishing this task.  Here is the relevant code:

the .aspx:
<telerik:RadGrid ID="rgPoOrders" runat="server" DataSourceID="dsPurchaseOrders"   
    GridLines="None">  
    <MasterTableView ItemStyle-HorizontalAlign="Center" AutoGenerateColumns="False" Width="95%"   
    DataKeyNames="cpono" DataSourceID="dsPurchaseOrders" GridLines="Horizontal" AlternatingItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">  
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
          
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
          
        <Columns> 
            <telerik:GridBoundColumn DataField="cpono" HeaderText="PO #" ReadOnly="True"   
                SortExpression="cpono" UniqueName="cpono">  
            </telerik:GridBoundColumn> 
            <telerik:GridBoundColumn DataField="DateOnly" DataType="System.DateTime"   
                HeaderText="Date Submitted" SortExpression="DateOnly" UniqueName="DateOnly">  
            </telerik:GridBoundColumn> 
            <telerik:GridHyperLinkColumn DataTextField="cshortrmk" HeaderText="Tracking #"   
                Target="_blank" UniqueName="cshortrmk" NavigateUrl="UpsTrack.aspx">  
            </telerik:GridHyperLinkColumn> 
        </Columns> 
          
        <ItemStyle HorizontalAlign="Center" /> 
        <AlternatingItemStyle HorizontalAlign="Center" /> 
        <HeaderStyle HorizontalAlign="Center" /> 
</MasterTableView> 
</telerik:RadGrid> 
 
<asp:ObjectDataSource ID="dsPurchaseOrders" runat="server"   
    OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"   
    TypeName="OrderEntryTableAdapters.POSelectCommandTableAdapter">  
    <SelectParameters> 
        <asp:SessionParameter Name="FName" SessionField="FName" Type="String" /> 
        <asp:SessionParameter Name="LName" SessionField="LName" Type="String" /> 
    </SelectParameters> 
</asp:ObjectDataSource> 

And here's the codebehind:
    Protected Sub rgPoOrders_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs) Handles rgPoOrders.SelectedIndexChanged  
 
        Dim TrackNum As String 
        Dim selectedItem As GridDataItem = rgPoOrders.SelectedItems(0)  
 
        TrackNum = selectedItem(rgPoOrders.MasterTableView.Columns(3)).Text  
        Session.Add("TrackNum", TrackNum)  
        test.Text = TrackNum  
 
    End Sub 

5 Answers, 1 is accepted

Sort by
0
robertw102
Top achievements
Rank 1
answered on 16 Mar 2010, 02:36 PM
The reason your current setup doesn't work is because it's just a link. It doesn't perform any postback, thus the reason it doesn't raise the SelectedIndexChanged event.

I would suggest using a GridTemplateColumn and add a LinkButton to it with the CommandName set to Select. This way the row the link is in will be selected and then you could retrieve the value you want from the SelectedIndexChanged event. The only thing you'll need to do is create a popup window using Javascript that sends the user to the link you want. You can accomplish this by assigning the Javascript method to the OnClientClick event of the LinkButton control.

I hope that helps.
0
TSCGlobal
Top achievements
Rank 1
answered on 16 Mar 2010, 02:49 PM
That does help a bit.  However I am not very familiar with javascript.  Could you provide some quick code to handle the popup, and where to put it?
0
Accepted
robertw102
Top achievements
Rank 1
answered on 17 Mar 2010, 02:59 PM
So you would create a GridTemplateColumn like so:

<telerik:GridTemplateColumn> 
                    <ItemTemplate> 
                        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="CommandName" OnClientClick="OpenPopupWindow()"></asp:LinkButton> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 

I setup the OnClientClick property to the javascript below:

<script type="text/javascript"
function OpenPopupWindow()  
window.open("<%=Page.ResolveUrl("~/UpsTrack.aspx")%>"); 
</script> 

In the javascript function I'm using the ResolveUrl function to return the full path to the page.

I hope that helps.
0
Mark Galbreath
Top achievements
Rank 2
answered on 17 Mar 2010, 04:09 PM
You can also use the url format option of the gridhyperlink API:

DataNavigateUrlFormatString = "list_LIN_detail.aspx?lin={0}&prevPage=LIN List" 

You can do almost anything when a user clicks on a hyperlink now.

Cheers!
Mark
0
ra ma
Top achievements
Rank 1
answered on 12 May 2010, 03:47 PM
how to set DataNavigateUrlFormatString value at client side(javascript)....
Tags
Grid
Asked by
TSCGlobal
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
TSCGlobal
Top achievements
Rank 1
Mark Galbreath
Top achievements
Rank 2
ra ma
Top achievements
Rank 1
Share this question
or