title: Bound value to a hiddenfield inside a datalist is not specific to an item
body: <p>I'm a beginner for asp.net(C#) and I'm working on a social networking application. I've stuck on the status update and comment section. I want that when page is loaded all the threads(status') should have their IDs in their hiddenfields inside the datalist as I've created an ItemTemplate for status and assigned Thread_ID to the hiddenfield. But the problem is that hiddenfield is not having different values for the different Items. I don't know where I'm doing the mistake. Please help me.</p>
  
  <p>Here is the code for datalist:</p>
  
  <pre><code>&lt;asp:DataList ID="DataListStatus" runat="server" RepeatColumns="1"
              onitemdatabound="DataListStatus_ItemDataBound"
              onitemcommand="DataListStatus_ItemCommand"&gt;
          &lt;ItemTemplate&gt;
              &lt;table width="550px"&gt;
                  &lt;tr&gt;&lt;asp:HiddenField ID="HFieldThreadID" Value='&lt;%#Eval("Thread_ID") %&gt;' runat="server" /&gt;
                      &lt;td style="vertical-align:top; width:50px;" align="left" rowspan="3"&gt;&lt;a href='UserProfile.aspx?loginid=&lt;%#Eval("RegID")%&gt;' &gt;&lt;img alt="Propic" src="../Images/ProPic.jpg" width="50px" height="50px" /&gt;&lt;/a&gt;&lt;/td&gt;
                      &lt;td style="vertical-align:top; width:250px;" align="left"&gt;&lt;a href='UserProfile.aspx?loginid=&lt;%#Eval("RegID")%&gt;' &gt;&lt;%#Eval("RegID")%&gt;&lt;/a&gt;&lt;/td&gt;
                      &lt;td style="vertical-align:top; width:250px;" align="right"&gt;&lt;%#Eval("St_Time") %&gt;&lt;/td&gt;
                  &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/ItemTemplate&gt;
  &lt;/asp:DataList&gt;
  </code></pre>
  
  <p>And here is the code behind:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      if (!IsPostBack)
      {
          da.SelectCommand = new SqlCommand("SELECT * FROM Status where RegID='" + Session["user"].ToString() + "'", con);
          con.Open();
          da.Fill(ds, "status");
          con.Close();
          DataListStatus.DataSource = ds.Tables["status"];
          DataListStatus.DataBind();
      }
  
  }
  </code></pre>
  
  <p>And here I'm using the hiddenfield's value in the inner datalist for the comments:</p>
  
  <pre><code>protected void DataListStatus_ItemDataBound(object sender, DataListItemEventArgs e)
  {
      da.SelectCommand = new SqlCommand("SELECT * FROM Comment WHERE Thread_ID='" +      ((HiddenField)e.Item.FindControl("HFieldThreadID")).Value + "'", con);
      con.Open();
      da.Fill(ds, "cmts");
      con.Close();
      ((DataList)e.Item.FindControl("DataListCmt")).DataSource = ds.Tables["cmts"];
      ((DataList)e.Item.FindControl("DataListCmt")).DataBind();
  }
  </code></pre>