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

x
  • 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" 
            DataSourceID="SqlDataSource1">
            <Columns>
                <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" />
 
	       <asp:BoundField>
                    <itemstyle horizontalalign="Center"  Width="30px" />
                    <itemtemplate>
                     <a href="internal.aspx?invoice_id=<%# Eval("cust_ID")%>"> delete</a>
                </itemtemplate>
               </asp:BoundField>
  
             
	    </Columns>
 
</asp:GridView>

Open in new window

0
tech_question
Asked:
tech_question
2 Solutions
 
newbiealCommented:
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:
http://www.netomatix.com/development/GridViewHideColumn.aspx

Hope this helps.
0
 
oobaylyCommented:
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

0

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