Converting a datagrid BoundColumn to a LinkButton

Posted on 2006-05-24
Last Modified: 2012-05-05
I have a datagrid that is dynamically built from a query. The number of columns will always be at least 2.

When my results are bound, how can I make the cells in columns 3 onwards, linkbuttons, rather than bound columns? I know I should do it in the ItemDataBound event, but it's the actual conversion of the cell I am having.
Question by:Craig_Muckleston
    LVL 17

    Accepted Solution

    in the itemDataDound event:

    e.Item.Cells(3).Text = "<a href='xxx.aspx'>text</a>"

    Author Comment

    Hi lem2802,

    Doesn't this turn it into a hyperlink though? What I want to do is have the linkbutton so that I can drill down into the datagrid without passing the user to another page.


    Author Comment


    I've managed to create the link buttons, but I can;t get any of it's events to fire...

    lnkBtn = New LinkButton
                    strColVal = e.Item.Cells(3).Text
                    With lnkBtn
                        .Text = strColVal
                        .Visible = True
                        .CommandName = "drill"
                        .CommandArgument = strColVal
                        .Enabled = True
                        .EnableViewState = True
                    End With
    LVL 6

    Expert Comment

    Edit the BoundColumn AND change it to Template
    In template you can do what ever you want.

    Hint using ur solution:
    Did you declare the CommandName ="drill" and catch it in OnItemCommand ?

    Author Comment

    HI lem2802,

    I have used your solution and passed params to another page. This works fine. I was looking for a way to do it in one page to be honest, but at least it works.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now