• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

how to get the text of hyperlink databound columns in datagrid

I have a datagrid in my webpage and the items are bound to datagrid in a hyper link, i mean datagrid will display one column of table from database which will be in hyper link, i want to get the text of hyperlink  when user click the hyper link text , which event i should use to store the clicked hyperlink text in session, please guide me
0
muneerz
Asked:
muneerz
  • 2
  • 2
1 Solution
 
aibusinesssolutionsCommented:
Use a template field and a link button, then intercept it in the ItemCommand function.

Something like this:
<asp:TemplateColumn>
    <ItemTemplate>
        <asp:LinkButton runat="server" Text='<%# Eval("URL") %>' CommandName="URLCLICK" CommandArgument='<% Eval("URL") %>' />
    </ItemTemplate>
</asp:TemplateColumn>

and in the code behind:
Protected Sub datagrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles datagrid1.ItemCommand
    If e.CommandName = "URLCLICK" Then
        Session("theUrl") = e.CommandArgument
    End If
End Sub
0
 
muneerzAuthor Commented:
this is not working , sorry
0
 
aibusinesssolutionsCommented:
Did you add a # to databind the CommandArgument?  I left it out by mistake.

<asp:LinkButton runat="server" Text='<%# Eval("URL") %>' CommandName="URLCLICK" CommandArgument='<%# Eval("URL") %>' />

I've tested it on my end and it works fine.

If e.CommandName = "URLCLICK" Then
            Session("theUrl") = e.CommandArgument
            Response.Write(Session("theUrl"))
End If
0
 
muneerzAuthor Commented:
thanks
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now