title: GridView Calculated Field
body: <p>I can create a custom link in my ASPX page like this:</p>
  
  <pre><code>&lt;asp:GridView 
  
      ID="GridView1" 
      CssClass="rounded-corner" 
      runat="server" 
      AutoGenerateColumns="false"
      EnableModelValidation="True" 
      AllowSorting="True"
      onsorting="GridView1_Sorting" 
      EnableViewState="true"
      AllowPaging="True"   
      PageSize="10"
      OnPageIndexChanging="GridView1_PageIndexChanging" &gt;
  
          &lt;Columns&gt;
              &lt;asp:BoundField DataField="DATE_ENTERED" HeaderText="Date Submitted" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" /&gt;
              &lt;asp:BoundField DataField="CLIENT_CLAIM_NUM" HeaderText="Your Claim #" /&gt;
              &lt;asp:BoundField DataField="PRIMARY_INSURED" HeaderText="Insured" /&gt;
              &lt;asp:BoundField DataField="PRIMARY_CLAIMANT" HeaderText="Claimant" /&gt;
              &lt;asp:BoundField DataField="LOB_ID" HeaderText="Type" /&gt;
  
              &lt;asp:TemplateField HeaderText="Branch"&gt;
                  &lt;ItemTemplate&gt;
                     &lt;asp:HyperLink ID="BRANCH_NAME" runat="server" NavigateUrl='&lt;%# "mailto:"+Eval("OWNERS_EMAIL") %&gt;' Text='&lt;%# Eval("BRANCH_NAME") %&gt;' ToolTip='&lt;%# 
                     "&lt;span style=\"text-decoration:underline;\"&gt;"+Eval("BRANCH_NAME").ToString().Trim() + "&lt;/span&gt;&lt;br /&gt;" + 
                     Eval("OWNERS_FIRST_NAME").ToString().Trim() + " " +
                     Eval("OWNERS_LAST_NAME").ToString().Trim() + "&lt;br /&gt;" + 
                     Eval("OWNERS_EMAIL").ToString().Trim() + "&lt;br /&gt;" + 
                     Eval("OWNERS_OFFICE_PHONE").ToString().Trim() + "&lt;br /&gt;" + 
                     Eval("OWNERS_FAX_PHONE").ToString().Trim()
                     %&gt; '&gt; 
                     &lt;/asp:HyperLink&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
  
          &lt;/Columns&gt;
  
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Is there, instead, a way to do this directly in my code behind; by creating a type of "calculated field?"</p>
  
  <p>The code behind is as follows:</p>
  
  <pre><code>DbProviderFactory dbf = DbProviderFactories.GetFactory();
  using ( IDbConnection con = dbf.CreateConnection() )
  {
      string sSQL;
      // 12/04/2006 Paul.  Only include active users. 
      sSQL = "select top 20                "         + ControlChars.CrLf
           + " DATE_ENTERED, CLIENT_CLAIM_NUM, PRIMARY_INSURED, PRIMARY_CLAIMANT, LOB_ID, BRANCH_NAME," + ControlChars.CrLf
           + " OWNERS_FIRST_NAME, OWNERS_LAST_NAME, OWNERS_NAME, OWNERS_EMAIL, OWNERS_OFFICE_PHONE, OWNERS_FAX_PHONE" + ControlChars.CrLf
           + "  from vwFILES_DetailViewWithOwners" + ControlChars.CrLf
           + " where 1 = 1                   " + ControlChars.CrLf;
      using ( IDbCommand cmd = con.CreateCommand() )
      {
          cmd.CommandText = sSQL;
  
          using ( DbDataAdapter da = dbf.CreateDataAdapter() )
          {
              ((IDbDataAdapter)da).SelectCommand = cmd;
              using ( DataTable dt = new DataTable() )
              {
                  da.Fill(dt);
                  vwMain = dt.DefaultView;
                  GridView1.DataSource = vwMain;
                  if ( !IsPostBack )
                  {
  
                      GridView1.DataBind();
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Can I simply create the new field in my code behind so I can call it like so:</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText="Branch"&gt;
      &lt;ItemTemplate&gt;
         &lt;asp:HyperLink ID="BRANCH_NAME" 
              runat="server" 
              NavigateUrl='&lt;%# "mailto:"+Eval("OWNERS_EMAIL") %&gt;' 
              Text='&lt;%# Eval("BRANCH_NAME") %&gt;' 
              ToolTip='&lt;%# Eval("MY_CALCULATED_FIELD") %&gt;'&gt; 
         &lt;/asp:HyperLink&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>Thanks for your advice.</p>