[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 736
  • Last Modified:

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

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

2 Solutions
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.
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now