Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you can determine the special column by its header text you can find out the column index and then, when you found the specific column change the cell's text in the RowDataBound event.</p> <p>This worked in my test:</p> <p><strong>ASPX:</strong></p> <pre><code>&lt;%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:GridView runat="server" ID="GridView1" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Code Beding:</strong></p> <pre><code>Partial Public Class _Default Inherits Page Private _specialColumnName As String = "DEF" Private _specialColumnIndex As Integer = -1 Private ReadOnly Property Data() As DataTable Get If Session("Default.Data") Is Nothing Then Dim value = New DataTable() Using connection = New SqlClient.SqlConnection("your_connection_string") Using command = connection.CreateCommand() command.CommandText = "SELECT * FROM your_table" Using adapter = New SqlClient.SqlDataAdapter(command) adapter.Fill(value) End Using End Using End Using 'value.Columns.Add("ABC", GetType(String)) 'value.Columns.Add("DEF", GetType(Integer)) 'value.Columns.Add("GHI", GetType(Boolean)) 'value.Rows.Add("A", 1, True) 'value.Rows.Add("B", 2, False) 'value.Rows.Add("C", 3, False) Session("Default.Data") = value End If Return CType(Session("Default.Data"), DataTable) End Get End Property Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load GridView1.DataSource = Data GridView1.DataBind() End Sub Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound If e.Row.RowType = DataControlRowType.Header Then For index As Integer = 0 To e.Row.Cells.Count - 1 If e.Row.Cells(index).Text = _specialColumnName Then _specialColumnIndex = index Return End If Next ElseIf _specialColumnIndex &gt; -1 AndAlso e.Row.RowType = DataControlRowType.DataRow Then e.Row.Cells(_specialColumnIndex).Text = "###" End If End Sub End Class </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload