I have a CheckBoxList
and I need to get the id
of each item in it on its DataBound
event and I don't know how to get it, please help me.
Here is my code:
HTML:
<asp:CheckBoxList ID="chklstArea"
RepeatColumns="6"
RepeatDirection="Vertical"
runat="server"
ondatabound="chklstArea_DataBound">
</asp:CheckBoxList>
here is code behind code:
protected void drpLocation_SelectedIndexChanged(object sender, EventArgs e)
{
if (drpLocation.SelectedItem.Value != "")
{
lbtnSelectArea.Visible = true;
objAreaNew = new ClsAreaNew();
ClsAreaNewProp objAreaNewProp = new ClsAreaNewProp();
objAreaNewProp.LocationId = Convert.ToInt64(drpLocation.SelectedItem.Value);
DataTable dtAreaByLocId = objAreaNew.GetAllAreaListByLocID(objAreaNewProp);
if (dtAreaByLocId.Rows.Count > 0)
{
divAreaListingHeader.Visible = true;
chklstArea.DataSource = dtAreaByLocId;
chklstArea.DataTextField = "AreaName";
chklstArea.DataValueField = "areaid";
chklstArea.DataBind();
lblStatusMessage.Text = "";
}
else
{
divAreaListingHeader.Visible = false;
dtAreaByLocId = null;
chklstArea.DataSource = dtAreaByLocId;
chklstArea.DataTextField = "AreaName";
chklstArea.DataValueField = "areaid";
chklstArea.DataBind();
lblStatusMessage.Text = "This Location does not have any area.";
}
}
else
{
lbtnSelectArea.Visible = false;
divAreaListingHeader.Visible = false;
chklstArea.DataSource = null;
chklstArea.DataTextField = "AreaName";
chklstArea.DataValueField = "areaid";
chklstArea.DataBind();
lblStatusMessage.Text = "Please select location.";
}
}
Actually what i need to do is: i need to bind another checkbox list on the bases of id of items binding in this checkbox list. like here i am binding areas. now i want to bind another checkbox list of rooms the id of area id i want to use to get rooms of that particular area.