通过Request.Form得到CheckBoxList当前所点选项的索引值


也即得到目前用户是点击了哪个Item项 触发了回发

页面HTML部分
------------
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"
 OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
    <asp:ListItem Value="1" Text="1a"></asp:ListItem>
    <asp:ListItem Value="2" Text="2b"></asp:ListItem>
    <asp:ListItem Value="3" Text="3c"></asp:ListItem>
    <asp:ListItem Value="4" Text="4d"></asp:ListItem>
</asp:CheckBoxList>

页面cs部分
------------
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
    //形如CheckBoxList1$2 其中CheckBoxList1为控件名 其后的2为触发回发事件的索引 索引从0开始
    string strCheck = Request.Form["__EVENTTARGET"].ToString();

    string strIndex = strCheck.Substring(strCheck.IndexOf("$")+1);
    this.TextBox1.Text = strIndex;
}

以上只是取得了点击的Item的索引
并没有判断用户是点选操作 还是 取消点选操作
更多功能可以再自动行添加

另 可参见 借助HiddenText 确定CheckBoxList当前的操作类型及点击的CheckBox

原文地址:https://www.cnblogs.com/freeliver54/p/1255749.html