Hello,

I'm trying access a checkbox in a datalist.

Here is the datalist:
<asp:DataList runat="server" ID="dlUserList"
onitemdatabound="dlUserList_ItemDataBound">
<ItemTemplate>
<table class="UserList" >
<tr>
<td>
   <asp:Label ID="lblForenames" runat="server" Text='<%# Eval
("Forenames") %>' CssClass="personForenames"></asp:Label>
</td>
<td>
  <input id="chkUserActive" type="checkbox" checked= '<%# Eval
("Active") %>' CssClass="personActive" />
</td>
<td>
  <a id="lnkEdit" class="button editButton" personID="<%# Eval
("PersonID") %>" >Edit</a>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

Here is the code behind:

$(document).ready(function() {
  initActions();
});

function initActions() {
  $(".editButton").click(function(e) {
    showUserDetails(this);
  });
}

function showUserDetails(currentEditButton) {
  var currentUser;
  currentUser = $(currentEditButton).closest(".UserList");

  var Forenames = ($(currentUser).find(".personForenames").html());
  // is active
  if ($('currentUser.personActive').is(':checked'))
  {
      //do something
  }
}

I can get the html value of the "lblForenames", but $
('currentUser.personActive') returns null.
I also tried $('currentUser #chkUserActive'), but it does not return
the checkbox either.

I cannot figure out why the same method could access a label but not a
checkbox?
I would be most appreciated if someone could please shine some light
on this issue.

Many thanks,

Lihong

Reply via email to