Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I Have a HTML Hyperlink in a Datagrid

I want to Assign the URL from that Hyperlink to a a variable

this is what i have done so far


aspx page

ASP.NET
<asp:TemplateColumn>                                                                                    <ItemTemplate>
<a id="Link" href="java<!-- no -->script:OpenAttachment('<%# DataBinder.Eval(Container, "DataItem.Link")%>');">
<%# DataBinder.Eval(Container, "DataItem.Link")%></a>
                                                                                    </ItemTemplate>                                                                                </asp:TemplateColumn>


in .cs page

C#
HtmlGenericControl Link = (HtmlGenericControl)lDgModel.FindControl("Link");


C#
string Link1 = Link. ?? .ToString();


what i have to enter in place of "??" to assign the URL to the variable

thank you
Posted
Updated 10-Dec-13 23:26pm
v2
Comments
Harshil_Raval 11-Dec-13 5:28am    
Href should work.
write2varun 11-Dec-13 5:33am    
"href" not there
Gitanjali Singh 11-Dec-13 5:43am    
Try NavigateUrl in place of ??
write2varun 11-Dec-13 5:47am    
"NavigateUrl" is not there

Hi,
try this.
C#
// in code behind
HtmlAnchor Link = (HtmlAnchor)lDgModel.FindControl("Link");
string Link1 = Link.Href; // here store navigate url in string variable

Hope it helps you.

EDIT
C#
foreach (GridViewRow fvr in lDgModel.Rows) // i assume lDgModel is your gridview id
{
    HtmlAnchor Link = (HtmlAnchor)lDgModel.FindControl("fvr");
    string Link1 = Link.Href;
}
// also keep runat="server" in a tag.
 
Share this answer
 
v2
Comments
write2varun 11-Dec-13 6:49am    
it is giving error when i am using runat="server" and "Object reference not set to an instance of an object." when not giving runat="server"
Harshil_Raval 11-Dec-13 7:06am    
To access any control one must have runat="server". otherwise it will not access on code behind.
write2varun 11-Dec-13 7:15am    
its giving error when im applying runat server
Harshil_Raval 11-Dec-13 7:18am    
ok.
in which method you are calling this..
HtmlAnchor Link = (HtmlAnchor)lDgModel.FindControl("Link");
write2varun 11-Dec-13 7:18am    
private DataTable GetDataFromGrid()
Link.NavigateUrl use for assign to link variable.
 
Share this answer
 
Comments
write2varun 11-Dec-13 5:36am    
"NavigateUrl" is not there
raneshtiwari 11-Dec-13 7:27am    
Yeah I saw, why you are not using hyperlink instead of link, you can achieve that things easily. or pass argument command for each link and then use link on click event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900