title: How to resize the table cell to fit the contents
body: <p>I have a GridView that I am using to display some contents:</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" AllowSorting="True" OnSorting="GridView1_Sorting" ClientIDMode="Static" runat="server" AutoGenerateColumns="False" EmptyDataText="No PDF was generated" OnRowCreated="GridView1_RowCreated"&gt;
          &lt;Columns&gt;
              &lt;asp:BoundField DataField="Text" HeaderText="File Name" SortExpression="FileName" &gt;
              &lt;HeaderStyle Width="15%" /&gt;
              &lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="Value" HeaderText="File Modified Date" SortExpression="FileDate" &gt;
              &lt;HeaderStyle Width="25%" /&gt;
              &lt;/asp:BoundField&gt;
              &lt;asp:TemplateField&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:LinkButton ID="lnkDownload" Text="Download" runat="server" CommandArgument='&lt;%# Container.DataItemIndex %&gt;' OnClick="DownloadFile" /&gt;
                  &lt;/ItemTemplate&gt;
                  &lt;HeaderStyle Width="15%" /&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:LinkButton ID="lnkView" Text="View in Browser" CommandArgument='&lt;%# Container.DataItemIndex %&gt;' OnClientClick="window.document.forms[0].target='blank';" runat="server" OnClick="ViewFile" /&gt;
                  &lt;/ItemTemplate&gt;
                  &lt;HeaderStyle Width="35%" /&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:ImageButton runat="server" ToolTip="Delete File" ID="lnkDelete" OnClientClick="confirmUser()" OnClick="DeleteFile" CommandArgument='&lt;%# Container.DataItemIndex %&gt;' ImageUrl="~/delete.png" Width="50px" Height="50px" /&gt;
                  &lt;/ItemTemplate&gt;
                  &lt;HeaderStyle Width="15%" /&gt;
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Which displays the following:</p>
  
  <p><img src="https://i.stack.imgur.com/h9XMz.png" alt="enter image description here"></p>
  
  <p>As you can see the second and the fourth column is too small. So I added the following code-behind to solve the issue:</p>
  
  <pre><code>protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.Header)
          {
              TableCell cell0 = e.Row.Cells[0];
              cell0.Width = new Unit("35%");
  
              TableCell cell1 = e.Row.Cells[1];
              cell1.Width = new Unit("20%");
  
              TableCell cell2 = e.Row.Cells[2];
              cell2.Width = new Unit("15%");
  
              TableCell cell3 = e.Row.Cells[3];
              cell3.Width = new Unit("15%");
  
              TableCell cell4 = e.Row.Cells[4];
              cell4.Width = new Unit("15%");
          }
      }
  </code></pre>
  
  <p>But the result is still the same. How can I modify/add to my code so that the first column  is smaller and the second and the fourth column is stretched out to ensure the contents are shown correctly?</p>