Create Dynamic Hyperlink in DataGrid Column

I have a project that i am working on.
And this project has a DataGrid in the ASP.net file

Here is what i want to accomplish
i want to have the last column of my datagrid be a dynamic link.
IE
ITEM ID             Descrip                    item_details
2161                 some item                 Details <------------i want this to be a link that looks like this http://somesite.com/itemdetails.aspx?item_id=2161

there is a list of about 21000 items so dynamicly is the the only way.
So how should i do this in Visual Studio?
Thanks
LVL 6
phoenixfire425Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

techprocessCommented:
Try this....
Firstly you'll need to take a template column.
In the template column, take a hidden control and a literal control.

Bind the hidden control value to something like
<asp:HiddenField id="hdnId" runat="server" value='<% #DataBinder.Eval(Container.DataItem,"ItemID") %>' />
And the literal control should look something like this.

<asp:Literal id="litLink" runat="server" />
Now in the ItemDataBound event of the gridview write this

I think this should work...


Literal litLink=(Literal)e.Row.FindControl("litLink");
HiddenField hdnID = (HiddenField)e.Row.FindControl("hdnId");
 
litLink.Text = "<a href='http://somesite.com/itemdetails.aspx?item_id='"+hdnID.value+">"

Open in new window

0
phoenixfire425Author Commented:
i tried what you said and it did not work.
however i did get this to work.

<asp:HyperLinkField DataNavigateUrlFields="order_no" DataNavigateUrlFormatString="OrderDetail.aspx?order_number={0}"
                    DataTextField="order_no" HeaderText="Order_details" SortExpression="order_no"
                    Target="_blank" />
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.