How to select and unselect the row in the GridView without having select button?
<p>I am developing a Master-Details GridView &amp; DetailsView. Everything works well, but what I want it to remove select button that I have in each row in the GridView and make the user be able to select the row by clicking anywhere in the row or by clicking on any cell in the row. Beside that, I want the details of each row to be displayed when he selects the row and hiding the details when he clicks again in the same row. <strong>So How to do that?</strong></p>

<p><strong>ASP.NET code:</strong></p>

<pre><code>&lt;asp:GridView ID="resultGrid" runat="server" DataKeyNames="QuestionID" SelectedIndex="0" 
                    AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="resultGrid_SelectedIndexChanged" Width="555px"&gt;
                        &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
                        &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" CssClass="generaltext" HorizontalAlign="Center" /&gt;
                        &lt;Columns&gt;
                            &lt;asp:CommandField ShowSelectButton="true" /&gt;
                            &lt;asp:BoundField DataField="QuestionID" HeaderText="Question" /&gt;
                            &lt;asp:BoundField DataField="UserAnswer" HeaderText="Your Answer" /&gt;
                            &lt;asp:BoundField DataField="Result" HeaderText="Result" /&gt;
                        &lt;/Columns&gt;
                        &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt;
                        &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt;
                        &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" CssClass="boldtext" /&gt;
                        &lt;EditRowStyle BackColor="#999999" /&gt;
                        &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
                    &lt;/asp:GridView&gt;
</code></pre>

<p><strong>Code-Behind code:</strong></p>

<pre><code>public partial class Results : System.Web.UI.Page
{
    bool bShowDetailsView;

    protected void Page_Load(object sender, EventArgs e)
    {
       bShowDetailsView = false;

        ArrayList al = (ArrayList)Session["AnswerList"];

        if (al == null)
        {
            Response.Redirect("default.aspx");
        }

        resultGrid.DataSource = al;
        resultGrid.DataBind();

        // Save the results into the database.
        if (IsPostBack == false)
        {
            // Calculate score
            double questions = al.Count;
            double correct = 0.0;


            for (int i = 0; i &lt; al.Count; i++)
            {
                Answer a = (Answer)al[i];
                if (a.Result == Answer.ResultValue.Correct)
                    correct++;
            }

            double score = (correct / questions) * 100;
            string username = HttpContext.Current.User.Identity.Name.ToString().Replace("ARAMCO\\", "");
            SqlDataSource userQuizDataSource = new SqlDataSource();
            userQuizDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["testConnectionString"].ToString();
            userQuizDataSource.InsertCommand = "INSERT INTO [UserQuiz] ([QuizID], [DateTimeComplete], [Score], [Username]) VALUES (@QuizID, @DateTimeComplete, @Score, @Username)";

            userQuizDataSource.InsertParameters.Add("QuizID", Session["QuizID"].ToString());
            userQuizDataSource.InsertParameters.Add("DateTimeComplete", DateTime.Now.ToString());

            // "N4" is for displaying four decimal places, regardless of what the value is 
            userQuizDataSource.InsertParameters.Add("Score", score.ToString("N4"));

            userQuizDataSource.InsertParameters.Add("Username", username);

            int rowsAffected = userQuizDataSource.Insert();
            if (rowsAffected == 0)
            {
                // Let's just notify that the insertion didn't
                // work, but let' s continue on ...
                errorLabel.Text = "There was a problem saving your quiz results into our database.  Therefore, the results from this quiz will not be displayed on the list on the main menu.";
            }

        }


    }


    protected void resultGrid_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlDataSource1.FilterExpression = "QuestionOrder=" + resultGrid.SelectedValue;
        bShowDetailsView = true;
        answerDetails.Visible = bShowDetailsView;
    }



}
</code></pre>
