好吧,尽可能简单,我有一个checkboxlist设置为true和OnSelectedIndexChanged的autopostback。但是,每次有人点击复选框中的项目时,页面都会刷新。我该如何阻止?我试过使用UpdatedPanel(这是一种工作)。如何停止页面刷新每次复选框是单击
<asp:CheckBoxList ID="Regions" runat="server" OnSelectedIndexChanged="Regions_SelectedIndexChanged" AutoPostBack="true" DataSourceID="SqlDataSource2" DataTextField="Regions" DataValueField="ID">
</asp:CheckBoxList>
OnselectedIndexChange显示一个复选框旁边的其他复选框的div。
protected void Regions_SelectedIndexChanged(object sender, EventArgs e)
{
string select = @"Select Facilities from [BulletinBoard].[DMHSAS\290974].[Facilities] ";
int[] ctr = new int[9];
int ctr1 = 0;
int counter = 0;
dFacilities.Style.Add("display", "block");
foreach (ListItem item in Regions.Items)
{
//Response.Write(item.Selected);
if (Regions.SelectedIndex == 0)
{
item.Selected = true;
CheckBoxList1.Visible = true;
counter++;
}
else if (item.Selected)
{
if (select.EndsWith("[Facilities] "))
{
select += "where ";
}
if (select.EndsWith(") "))
{
select += " or ";
}
select += " (Reg_ID = " + Regions.SelectedIndex + ") ";
ctr[ctr1 + 1] = Regions.SelectedIndex;
item.Selected = false;
counter++;
CheckBoxList1.Visible = true;
}
ctr1++;
}
if (counter == 0)
{
CheckBoxList1.Visible = false;
dFacilities.Style.Add("display", "none");
}
ctr1 = 0;
bool all = false;
foreach (int counter1 in ctr)
{
Regions.Items[counter1].Selected = true;
if (Regions.Items[0].Selected == true)
foreach (ListItem item in Regions.Items)
{
if (item.Selected)
{
all = true;
}
else
{
all = false;
break;
}
}
if (all == false)
{
Regions.Items[0].Selected = false;
}
}
所以它与'UpdatePanel'工作或没有?无论如何你还没有展示过它。 – 2014-09-02 20:36:21
OP说使用updatepanel它的工作方式! – rach 2014-09-02 20:41:49
'UpdatePanel'只是简单的屏蔽了页面刷新。你还在做回发。如果你不想刷新页面,为什么不把'autopostback'设置为'false'? – Mrchief 2014-09-02 20:43:15