我有一個CheckBoxList
,我需要在其DataBound
事件中獲得其中每個項目的id
,我不知道如何獲取它,請幫助我。如何獲取checkboxlists數據綁定事件中每個項目的id?
這裏是我的代碼:
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來獲取該特定區域的房間。
你如何填寫你的項目? –
@AmiramKorach請參閱最新的問題 – Ram