title: How to bind repeater ItemDataBound, to update on dropdownlist SelectedIndexChanged
body: <p>Im a rookie on ASP.Net and been stuck for this for a while.</p>
  
  <p>Everytime the index of my dropdown changes i want to fill my repeater with objects.</p>
  
  <p>This works fine, but when im selecting a value in my dropdown that dosent contain any objects the old objects from the last call is still there, i want them to disappear.</p>
  
  <p>I've tried to clear the items from the repeater using Datasource=null and then do a Databind again, but that dosent work.</p>
  
  <p>I think it has with the ItemDataBound event on my repeater. 
  The ItemDatabound is not called when i select a value in the dropsdownlist that dosent contain any objects.</p>
  
  <p><strong>ItemDataBound CODE:</strong></p>
  
  <pre><code>protected void rptStudentQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
      {
          Label lblAnswer = e.Item.FindControl("lblAnswer") as Label;
          TextBox tbxAnswer = e.Item.FindControl("tbxAnswer") as TextBox;
          Button btnSend = e.Item.FindControl("btnSend") as Button;
          if (lblAnswer.Text == "" || lblAnswer == null)
          {
              lblAnswer.Visible = false;
              lblAnswer.Enabled = false;
              tbxAnswer.Visible = true;
              tbxAnswer.Enabled = true;
              btnSend.Enabled = true;
              btnSend.Visible = true;
          }
          else
          {
              lblAnswer.Visible = true;
              lblAnswer.Enabled = true;
              tbxAnswer.Visible = false;
              tbxAnswer.Enabled = false;
              btnSend.Enabled = false;
              btnSend.Visible = false;
  
          }
      }
  }
  </code></pre>
  
  <p><strong>OnSelectedIndexChanged CODE:</strong></p>
  
  <pre><code>protected void DrpdwnLectureName_SelectedIndexChanged(object sender, EventArgs e)
  {
      string SelectedLecture = DrpdwnLectureName.SelectedValue;
      string user = Server.HtmlEncode(Context.User.Identity.Name).ToString();
      using (var client = new WCFReference.SRSServiceClient())
      {
          var LectureList = client.GetTeacherLecture(user);
          foreach (var item in LectureList)
          {
              if (item.LectureName == DrpdwnLectureName.SelectedValue)
              {
                  var list = client.GetStudentQuestions(item.LectureID, user);
                  rptStudentQuestion.DataSource = list;
                  rptStudentQuestion.DataBind();
              }
          }               
  
      }
  
  }
  </code></pre>
  
  <p><strong>Markup CODE:</strong></p>
  
  <pre><code>&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
          &lt;ContentTemplate&gt;
              &lt;asp:DropDownList ID="DrpdwnLectureName" AutoPostBack="True" runat="server" OnSelectedIndexChanged="DrpdwnLectureName_SelectedIndexChanged"&gt;&lt;/asp:DropDownList&gt;
              &lt;asp:Panel ID="PrintPanel" runat="server"&gt;
                  &lt;asp:Label ID="Label1" runat="server" Text="Gör en .pdf på besvarade frågor"&gt;&lt;/asp:Label&gt;
                  &lt;asp:Button ID="btnDoPdf" runat="server" Text="Button" OnClick="btnDoPdf_Click" /&gt;
              &lt;/asp:Panel&gt;
              &lt;asp:Repeater ID="rptStudentQuestion" runat="server" OnItemCommand="rptStudentQuestion_ItemCommand" OnItemDataBound="rptStudentQuestion_ItemDataBound"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lblQuestion" runat="server" Text='&lt;%# Eval("StudentQuestionQuestion") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;br /&gt;
                      &lt;asp:TextBox ID="tbxAnswer" runat="server" Visible="false"&gt;&lt;/asp:TextBox&gt;
                      &lt;asp:Button ID="btnSend" CommandName="SendAnswer" runat="server" Text="Skicka svar" CommandArgument='&lt;%# Eval("StudentQuestionID") %&gt;' /&gt;
                      &lt;br /&gt;
                      &lt;asp:Label ID="lblAnswer" runat="server" Text='&lt;%# Eval("StudentQuestionAnswer") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                      &lt;br /&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:Repeater&gt;
          &lt;/ContentTemplate&gt;
      &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>Updated Code as Requested(Snippet from DrpdwnLectureName_SelectedIndexChanged)</p>
  
  <pre><code>if (item.LectureName == DrpdwnLectureName.SelectedValue)
  {
      var list = client.GetStudentQuestions(item.LectureID, user);
      if (list.Count() &gt; 0)
      {
          rptStudentQuestion.Visible = true;
          rptStudentQuestion.DataSource = list;
          rptStudentQuestion.DataBind();
      }
      else
      {
          rptStudentQuestion.Visible = false; // In debug it preforms this, but nothing happens.                            
      }
  }
  </code></pre>