您可以在CheckBoxList的SelectedIndexChanged
事件中执行此操作。
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged"></asp:CheckBoxList>
后面的代码
protected void CheckBoxList1_SelectedIndexChanged(object sender,EventArgs e)
{
//get the index of the last changed checkbox
int index = Convert.ToInt32(Request.Form["__EVENTTARGET"].Split('$').Last());
//find the correct listitem in the checkboxlist
ListItem item = CheckBoxList1.Items[index];
//if the item is already in first position do nothing
if (index == 0)
return;
//remove it from it's current position
CheckBoxList1.Items.RemoveAt(index);
//add the listitem at the top
CheckBoxList1.Items.Insert(0,item);
}
这可能不适用于DataSourceID
。因此,如果不是这样,则必须从后面的代码开始将数据绑定到CheckBoxList:http://www.dotnetfox.com/articles/how-to-bind-data-to-checkboxlist-control-in-Asp-Net-using-C-Sharp-1042.aspx
本文链接:https://www.f2er.com/3139460.html