Select a value from dropdown depending on the value from the Sql table
<p>In the add page i have a dropdown which has got two listitems M and F.I have also got a table which store the value of the dropdown . In the edit page i have got the same dropdown with the same listitems,and i would  like to have that value of the dropdown (listitem)selected depending on the value stored in the sql table.
Using the code below i get this error:System.NullReferenceException: Object reference not set to an instance of an object.</p>

<p>.aspx code</p>

<pre><code>&lt;asp:DropDownList ID="DriverGender" runat="server"&gt;
                        &lt;asp:ListItem  &gt;M&lt;/asp:ListItem&gt;
                        &lt;asp:ListItem &gt;F&lt;/asp:ListItem&gt;
                    &lt;/asp:DropDownList&gt;
</code></pre>

<p>.aspx.cs code</p>

<pre><code>String SqlSelectDriverDetails = "SELECT * FROM driver WHERE driverID = @IdFromUrl";

            //Create SqlCommand object
            SqlCommand SqlComm = new SqlCommand(SqlSelectDriverDetails, DBConn);

            //Passing parameters to the sql query
            SqlComm.Parameters.Add("@IdFromUrl", SqlDbType.Int).Value = ID;

            //Creating DataReader object
            SqlDataReader DataReaderObj;
            DataReaderObj = SqlComm.ExecuteReader();

            //if the resultant is not empty
            while (DataReaderObj.Read())
            {

                string gender = (String)DataReaderObj["gender"];

DriverGender.Items.FindByValue((String)DataReaderObj["gender"]).Selected = true;
             }
</code></pre>
