title: How to get the text of a hyperlink field inside a grid view in ASP .Net?
body: <p>In my case my grid view can contain normal text or a hyperlink . I want to get the value of those fields. So far I have tried </p>
  
  <pre><code>        DataTable detailTable = new DataTable();
          for (int i = 0; i &lt; gvTransactionDetails.Columns.Count; i++)
          {
              detailTable.Columns.Add(gvTransactionDetails.HeaderRow.Cells[i].Text.ToString());
          }
  
          foreach (GridViewRow gvrow in gvTransactionDetails.Rows)
          {
              DataRow dr = detailTable.NewRow();
              for (int j = 0; j &lt; gvTransactionDetails.Columns.Count; j++)
              {
                  Control hyperLink = gvrow.Cells[j].Controls[0] as LiteralControl;
  
                  if (hyperLink != null)
                  {
                      dr[j] = ((LiteralControl)gvrow.Cells[j].Controls[0]).Text.ToString();
                  }
                  else
                  {
                      dr[j] = gvrow.Cells[j].Text.ToString();
                  }
              }
  
              detailTable.Rows.Add(dr);
          }
  </code></pre>
  
  <p>The problem I am facing is as the first cell in each and every row is a hyperlink and rest all other cells only contain text values, after the first iteration of the foreach loop only I am getting "Specified argument was out of the range of valid values.
  Parameter name: index" exception.</p>
  
  <p>Any idea how to fix it ? </p>