how can dynamically change the text of a column in gridview ?

Posted on 2009-04-16
Last Modified: 2012-05-06
how to change the text of a dynamically bound column in gridview depending on data values ?
eg: in the below customer gridview , I do not want to show the  href at the bottom of the grid for microsoft i.e. when the  CompanyName is microsoft I do not want to show the delete hyperlink ? How can I achieve this ?

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 

            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID" 



                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" 

                    SortExpression="CustomerID" />

                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" 

                    SortExpression="CompanyName" />

                <asp:BoundField DataField="ContactName" HeaderText="ContactName" 

                    SortExpression="ContactName" />

                <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" 

                    SortExpression="ContactTitle" />

                <asp:BoundField DataField="Address" HeaderText="Address" 

                    SortExpression="Address" />

                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />

                <asp:BoundField DataField="Region" HeaderText="Region" 

                    SortExpression="Region" />

                <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" 

                    SortExpression="PostalCode" />


                    <itemstyle horizontalalign="Center"  Width="30px" />


                     <a href="internal.aspx?invoice_id=<%# Eval("cust_ID")%>"> delete</a>







Open in new window

Question by:tech_question
    LVL 4

    Accepted Solution

    If I understand the problem correctly, you want to hide the field if company MS has been selected.  If this is correct, then the following will give you some basic ideas how to do this:

    Hope this helps.
    LVL 15

    Assisted Solution

    Add a Composite column to you select statement, ie:
    IIF(CompanyName == 'Microsoft', 'False', 'True') AS [Href_Visible

    then add the following binding to the link:

    <a href="internal.aspx?invoice_id=<%# Eval("cust_ID")%>" Visible='<%# Eval("Href_Visible")%>'> delete</a>

    Open in new window


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    730 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

    17 Experts available now in Live!

    Get 1:1 Help Now