我的aspx页面中有一个复选框列表,如下所示。 chklstOptions必须允许用户选择RepOptionA或RepOptionB,并且不应同时选中这两个复选框。
例如,当用户在已选中RepOptionA时选择RepOptionB时,必须取消选中RepOptionA并检查RepOptionB。此外,用户可以在没有任何约束的情况下检查/取消选中OptionA,OptionB和OptionC等其他选项。有人可以提出一种方法来实现这个
<asp:CheckBoxList ID="chklstOptions" runat="server" RepeatColumns="2" RepeatDirection="Horizontal" Enabled="false" OnSelectedIndexChanged="chklstOptions_SelectedIndexChanged" OnTextChanged="chklstOptions_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="OptionA" Value="OptionA" ></asp:ListItem>
<asp:ListItem Text="OptionB" Value="OptionB" ></asp:ListItem>
<asp:ListItem Text="OptionC" Value="OptionC" ></asp:ListItem>
<asp:ListItem Text="RepOptionA" Value="RepOptionA" ></asp:ListItem>
<asp:ListItem Text="RepOptionB" Value="RepOptionB" ></asp:ListItem>
</asp:CheckBoxList>
到目前为止,我尝试了以下代码,这没有任何帮助
protected void chklstOptions_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem Item in chklstOptions.Items)
{
if (Item.Selected)
{
if (Item.Text == "RepOptionB")
{
if (chklstOptions.Items.FindByText("RepOptionA").Selected == true)
chklstOptions.Items.FindByText("RepOptionA").Selected = false;
chklstOptions.Items.FindByText("RepOptionB").Selected = true;
}
if (Item.Text == "RepOptionA")
{
if (chklstOptions.Items.FindByText("RepOptionB").Selected == true)
chklstOptions.Items.FindByText("RepOptionB").Selected = false;
chklstOptions.Items.FindByText("RepOptionA").Selected = true;
}
}
}
}
答案 0 :(得分:1)
试试这个
for el in df['diff_time']:
if el > a:
el = b
else:
el = continue
答案 1 :(得分:0)
最后用下面的代码实现它,使用最后选择的复选框listitem值..: - )
protected void chklstOptions_SelectedIndexChanged(object sender, EventArgs e)
{
var selectedItem = chklstOptions.SelectedItem;
string result = Request.Form["__EVENTTARGET"];
string[] checkedBox = result.Split('$'); ;
int index = int.Parse(checkedBox[checkedBox.Length - 1]);
string latestItem = chklstOptions.Items[index].Value;
foreach (ListItem Item in chklstOptions.Items)
{
if (Item.Selected)
{
if (Item.Text == "RepOptionA" && latestItem == "RepOptionB")
{
chklstOptions.Items.FindByText("RepOptionA").Selected = false;
chklstOptions.Items.FindByText("RepOptionB").Selected = true;
}
if (Item.Text == "RepOptionB" && latestItem == "RepOptionA")
{
chklstOptions.Items.FindByText("RepOptionB").Selected = false;
chklstOptions.Items.FindByText("RepOptionA").Selected = true;
}
}
}
}