title: Get column index values in gridview
body: <p>I am having a gridview in asp.net, and in the table I have two columns.
  Now I must show the column index value row by row on the button click in form of a alert for dllDesc and txtBoxDesc fields.</p>
  
  <pre><code>&lt;asp:GridView ID="gvCar" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataKeyNames="LevelID" OnRowDataBound="gvCar_RowDataBound"&gt;
              &lt;AlternatingRowStyle BackColor="White" /&gt;
              &lt;Columns&gt;
                  &lt;asp:TemplateField HeaderText="Car"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="Car" runat="server" Width="150px" Height="30px" Font-Names="Georgia" MyCustomAttr="foo" margin-Left="100px" Text='&lt;%# Bind("CharName") %&gt;'&gt;&lt;/asp:Label&gt;
  
  
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Description"&gt;
                      &lt;ItemTemplate&gt;
  
                           &lt;asp:DropDownList ID="ddlDesc" Width="142px" Height="35px" Font-Names="Georgia" margin-Left="100px" runat="server"&gt;
                           &lt;/asp:DropDownList&gt;
  
                          &lt;asp:TextBox ID="txtBoxDesc" runat="server" Width="130px" Height="28px" Font-Names="Georgia" margin-Left="100px" Text=''&gt;&lt;/asp:TextBox&gt;
  
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  
              &lt;/Columns&gt;
  
          &lt;/asp:GridView&gt; 
  &lt;asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /&gt;
  </code></pre>
  
  <p>I managed to get the value for rows(code below) but i could not find a way to show it for columns.</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      foreach (GridViewRow gvr in gvCar.Rows)
      {
          string PrimaryKey = gvCar.DataKeys[gvr.RowIndex].Values[0].ToString();
          MessageBox.Show(PrimaryKey);
      }
  }
  </code></pre>
  
  <p>Can someone help me please?</p>