title: How to display selected row value/text inside the dropdown
body: <p>So I am new to using ASP.net and i have a hard time displaying the value/text of the selected row inside the dropdown. I just want to select a row in the griview and when i select, the values in it should populate the textboxes and dropdown, can someone help me ? thanks</p>
  
  <p>this is my code behind, as you can see in the LoadData() part I used the .findtext() but it outputs an error :Object reference not set to an instance of an object.</p>
  
  <pre><code>protected void grdRecentCases_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
     {
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';this.style.cursor='Pointer'";
             e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
             e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.grdRecentCases, "Select$" + e.Row.RowIndex);
         }
     }
  
  
     protected void grdRecentCases_RowCommand(Object sender, GridViewCommandEventArgs e)
     {
         if (e.CommandName == "Select")
         {
             LoadData(Convert.ToInt32(e.CommandArgument));
  
         }
     }
  
     ///&lt;summary&gt; LoadData is used to populate inputboxes with the value of the selected griview row&lt;/summary&gt;
     ///&lt;param name="rowNumber"&gt; Indicates whether there is a selected row or non&lt;/param&gt;
     private void LoadData(int? rowNumber = null)
     {
         //if rowNumber is null use GridView1.SelectedIndex
         var index = rowNumber ?? grdRecentCases.SelectedIndex;
  
         //Populate the input box with the value of selected row.
         GridViewRow gr = grdRecentCases.Rows[index];
         txtDepartmentCase.Text = gr.Cells[2].Text;
         txtLabCase.Text = gr.Cells[5].Text;
         txtIncidentReportDate.Text = gr.Cells[6].Text;
         txtCaseKey.Text = gr.Cells[1].Text;
         drpDepartment.Items.FindByText(gr.Cells[3].Text).Selected = true;
         drpCharge.Items.FindByText(gr.Cells[4].Text).Selected = true;
  
     }
  </code></pre>
  
  <p>Html code </p>
  
  <pre><code>&lt;table class="style2"&gt;
              &lt;tr&gt;
                  &lt;td class="style3"&gt;
                      Department Case #
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="txtDepartmentCase" runat="server" Enabled="False"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="style3"&gt;
                      Department
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:DropDownList ID="drpDepartment" runat="server" Height="18px" Width="153px" Enabled="False"
                          AppendDataBoundItems="true" AutoPostBack="true" OnSelectedIndexChanged="drpDepartment_SelectedIndexChanged"
                          Visible="true"&gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;asp:TextBox ID="txtDepartment" runat="server" Enabled="False"&gt;&lt;/asp:TextBox&gt;
  
  
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="style3"&gt;
                      Charge
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:DropDownList ID="drpCharge" runat="server" Height="22px" Width="153px" Enabled="False"
                          AppendDataBoundItems="true" AutoPostBack="true"  OnSelectedIndexChanged="drpCharge_SelectedIndexChanged"
                          Visible="true"&gt;
                      &lt;/asp:DropDownList&gt;
                      &lt;asp:TextBox ID="txtCharge" runat="server" Enabled="False"&gt;&lt;/asp:TextBox&gt;
  
  
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="style3"&gt;
                      Lab Case #
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="txtLabCase" runat="server" Enabled="False"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="style3"&gt;
                      Incident Report Date
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="txtIncidentReportDate" runat="server" Enabled="False"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  </code></pre>