我有一个CheckBoxList
,我需要id
在其DataBound
活动中获取其中的每个项目,但我不知道如何获取它,请帮助我。
这是我的代码:
HTML:
<asp:CheckBoxList ID="chklstArea"
RepeatColumns="6"
RepeatDirection="Vertical"
runat="server"
ondatabound="chklstArea_DataBound">
</asp:CheckBoxList>
这是代码背后的代码:
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.";
}
}
实际上我需要做的是:我需要在此复选框列表中绑定的项目 id 的基础上绑定另一个复选框列表。像这里我是绑定区域。现在我想绑定另一个房间的复选框列表,我想使用区域 id 的 id 来获取该特定区域的房间。