我有两个CheckBoxList控件-- chk1和chk2。如果选择了另一个CheckBoxList,则需要使用异步回发来清除对该use的选择。如果有选择,并且选中了项目chk2,则不会清除chk1:
<asp:ScriptManager ID="sm1" runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="upd" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="chk1" />
<asp:AsyncPostBackTrigger ControlID="chk2" />
</Triggers>
<ContentTemplate>
<asp:Label ID="result" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<div style="overflow: auto; height: 150px;">
<asp:CheckBoxList runat="server" ID="chk1" OnDataBound="assignClickBehaviours" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
<asp:ListItem Value="100" Text="..."></asp:ListItem>
<asp:ListItem Value="150" Text="One hundred and Fifty"></asp:ListItem>
</asp:CheckBoxList>
</div>
<div style="overflow: auto;">
<asp:CheckBoxList runat="server" ID="chk2" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
</asp:CheckBoxList>
</div>代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
processChecks();
}
private void processChecks()
{
if(chk2.SelectedIndex>-1)
chk1.ClearSelection();
}如果把整个东西放到更新面板里,它就能工作了.但由于复选框中可能有150个项目,如果选中了底部的项目,则overflow:auto上的滚动将弹回顶部。我需要滚动状态保持不动(因此需要异步回发)。有什么想法或选择吗?
发布于 2011-09-29 21:41:26
你可以试试这段代码..
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="sm1" runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="upd" runat="server">
<ContentTemplate>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="chk1">
</asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="chk1">
</asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
<div style="overflow: auto; height: 150px;">
<asp:CheckBoxList runat="server" ID="chk1" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
<asp:ListItem Value="100" Text="..."></asp:ListItem>
<asp:ListItem Value="150" Text="One hundred and Fifty"></asp:ListItem>
</asp:CheckBoxList>
</div>
<div style="overflow: auto;">
<asp:CheckBoxList runat="server" ID="chk2" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
</asp:CheckBoxList>
</div>
</form></body>发布于 2011-10-17 12:22:29
请尝试使用此代码,
processChecks(); 请进行以下更改,请注意EventName 'SelectedIndexChanged‘
<asp:ScriptManager ID="sm1" runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="upd" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="chk1" EventName="SelectedIndexChanged"/>
<asp:AsyncPostBackTrigger ControlID="chk2" EventName="SelectedIndexChanged"/>
</Triggers>
<ContentTemplate>
<asp:Label ID="result" runat="server" />
<div style="overflow: auto; height: 150px;">
<asp:CheckBoxList runat="server" ID="chk1" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
<asp:ListItem Value="100" Text="..."></asp:ListItem>
<asp:ListItem Value="150" Text="One hundred and Fifty"></asp:ListItem>
</asp:CheckBoxList>
</div>
<div style="overflow: auto;">
<asp:CheckBoxList runat="server" ID="chk2" AutoPostBack="true">
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
<asp:ListItem Value="3" Text="Three"></asp:ListItem>
</asp:CheckBoxList>
</div>
</ContentTemplate>
</asp:UpdatePanel>https://stackoverflow.com/questions/7597914
复制相似问题