Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
1.40/5 (2 votes)
See more:
LinkButton lnkBtn = (LinkButton)e.CommandSource; // the button
GridViewRow myRow = (GridViewRow)lnkBtn.Parent.Parent; // the row
GridView myGrid = (GridView)sender; // the gridview
string ID = myGrid.DataKeys[myRow.RowIndex].Value.ToString();

here i got id as www.google.com,, now i want to assign it to link or hyperlink buttom so that it must open that link
Posted
Comments
[no name] 19-Mar-14 2:24am    
Your question not Complete ....please give more details ...

try this .first you bind the grid in code behind ( Url from Database retrieve and add dynamically to grid >

<asp:grdivw id='g1' runat=server>
<asp:TemplateField Headertext="linkheadder">
<itemtemlate>

click on smart tag of gridview and click on add new column. There you will get add field options. Check it.
 
Share this answer
 
Comments
Member 9893329 19-Mar-14 1:08am    
YA I GOT IT BUT BY CLICKING THE LINK IT SHOWING ERROR.. IT IS SHOWING LIKE
Requested URL: /JOBS/www.infosys.com
IT IS NAVINGATING WITHIN MY PROJECT BUT I WANT TO NAVIGATE TO THE WEBSITE GIVEN
Hi

I think you are populated your Gridview from SQL. Now let us say that you have a column LINK in Gridview which contains URL. Now go to grid view smart tag and click on Add new column. Select choose a field type as Hyperlink field. Provide a Header Text.Select correct field from get text from data field.Select correct field from get URL from data field. Set Target to _blank.So url will be opened in new tab.Click ok.
build and run.When you click the link it will open that link.

Good Luck.
 
Share this answer
 
v2
Comments
Member 9893329 19-Mar-14 4:56am    
again it is showing error like
The resource cannot be found.
Requested URL: /JOBS/www.hcl.com
Please review the following URL and make sure that it is spelled correctly.

it is searching from my build application
Yeah. I observed it. I tried it with http://Google.com and it was redirecting to that. I will check for solutions.
 
Share this answer
 
Comments
Member 9893329 19-Mar-14 6:03am    
please give me the solution
Ajith K Gatty 19-Mar-14 6:07am    
you are getting error 404 right?? when you try to click on URL: /JOBS/www.hcl.com ?
Member 9893329 19-Mar-14 6:20am    
yeah? i am getting same error
Ajith K Gatty 19-Mar-14 6:45am    
I guess the problem is in the URL.Try Fully qualified URLS.
This is my Gridview.

XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
><Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" InsertVisible="False" ReadOnly="True" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Author" HeaderText="Author" SortExpression="Author" />
                <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
                <asp:BoundField DataField="Cost" HeaderText="Cost" SortExpression="Cost" />
                <asp:BoundField DataField="Rating" HeaderText="Rating" SortExpression="Rating" />
                <%--<asp:BoundField DataField="Link" HeaderText="Link" SortExpression="Link" />--%>
                <asp:HyperLinkField DataNavigateUrlFields="Link" DataTextField="Link" HeaderText="Link" Target="_blank" />
            </Columns>
        </asp:GridView>
 
Share this answer
 
Comments
Member 9893329 19-Mar-14 6:23am    
same code i wrote but again it is getting the same error like
The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /JOBS/WWW.INFOSYS.COM
Ajith K Gatty 19-Mar-14 6:32am    
yes. Those urls are giving error.You just check with other urls once to make sure that site is redirecting properly. use this link http://www.hclisd.com/apply-jobs.aspx or http:google.com. update me with result.
<asp:hyperlink id="hlnkbtn" text="Details" runat="server" navigateurl="<%#" http:="" "+convert.tostring(eval("website"))="" %&gt;"="" xmlns:asp="#unknown">

it will solves the problem
 
Share this answer
 

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