title: How to highlight a selected row in a gridview?
body: <p>I am adding a dropdown to gridview using template field as:</p>
  
  <pre><code> &lt;asp:TemplateField HeaderText="Change Color"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:DropDownList ID="dropdownid" DataSourceID="sqldatasource_id" DataTextField="username"
                              BackColor="GrayText"  OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AppendDataBoundItems="True" runat="server" AutoPostBack="True"&gt;
  
                              &lt;asp:ListItem Text="--Select One--" Value="" Selected="True" /&gt;
                          &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>SqlDataSource is:</p>
  
  <pre><code> &lt;asp:SqlDataSource ID="sqldatasource_id" runat="server" ConnectionString="&lt;%$ ConnectionStrings:crudconnection %&gt;"
              SelectCommand="SELECT [username] FROM [crudtable]"&gt;&lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Indexchange-Event is as :</p>
  
  <pre><code> protected void GridView1_SelectedIndexChanged(object sender,EventArgs e)
      {
  
  
      }
  </code></pre>
  
  <p>I want to highlight a row when any value from the corresponding dropdownlist is selected.
  How can i do it?</p>
  
  <p>Thanks in advance.</p>
  
  <hr>
  
  <p>i tried it:</p>
  
  <pre><code>  GridView1.Rows[GridView1.SelectedIndex].BackColor = Color.Red;
  </code></pre>
  
  <p>But still it is giving a exception as follow when-ever i select any value from any dropdownlist.</p>
  
  <p><strong>Index was out of range. Must be non-negative and less than the size of the collection.
  Parameter name: index</strong></p>
  
  <p>I am getting index number of selected row as already mentioned.can't i increment it from there and can use back-color property too?</p>