开发者

How to Call an event when a specific item on CheckBoxList is clicked?

I've got a CheckBoxList, which is populated via .DataSource, getting some items from the database. Each one if this items got it's ID according to the ID on its database record.

What I need is, when the user clicks item with ID 34, it shows him a panel/popup... I already have everything, the开发者_开发问答 popup and all. Just don't know how to capture this last item cliked.


try the following (and adapt it to your situation):

<asp:CheckBoxList ID="CheckBoxList1" runat="server" 
    onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
</asp:CheckBoxList>

Your codebehind might look something like this:

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e) {
    CheckBoxList cbl = sender as CheckBoxList;
    Response.Write(cbl.SelectedIndex);
    Response.Write(cbl.SelectedItem);
}

Check if SelectedItem, Value or Index has the value you're looking for and you're done.


protected void chkServicos_SelectedIndexChanged(object sender, EventArgs e)
    {
        CheckBoxList cbl = sender as CheckBoxList;
        Response.Write("SelectedItem: " + cbl.SelectedItem.Value.ToString());

I did this and it won't work as the .SelectedItem only gives me the first item on the entire list that is selected.. i need to capture the one that i just clicked in..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜