如何在不使用asp.net中的按钮的情况下在列表框中显示checkboxlist值? [英] How to display checkboxlist values in a listbox without using of button in asp.net ?

查看:89
本文介绍了如何在不使用asp.net中的按钮的情况下在列表框中显示checkboxlist值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框列表,它的值是Max Payne,Hitman,使命召唤等等。现在我的问题是每当我点击任意或所有这些复选框时,就会有值(Max Payne,Hitman等)将显示在列表框中(列表框在我的webform中)。请在C#中给出完整的编码。

Thanx提前.....

I have a checkboxlist and it''s values are "Max Payne","Hitman","Call Of Duty" etc. Now my question is that whenever i"ll click on any or all of these checkboxes then there values("Max Payne","Hitman" etc.) will be displayed in a listbox(listbox is there in my webform). please give full coding in C#.
Thanx in advance.....

推荐答案

这不是一个完整的编码,更像是提示。

然而,我觉得它几乎接近完整的编码。



尝试填补剩下的空白。



ASP.NET中的每个控件都有一个名为 AutoPostBack 的属性。

AutoPostBack的功能就像一个按钮的点击事件。

如果有的话对控件进行的更改,它将执行回发事件。

接下来,ASP.NET控件需要一个操作事件供您处理代码背后。

在你的情况下,你需要CheckBoxList'的 Sel ectedIndexChanged 动作事件。



ASP.NET页面编码示例:

This is not a full coding, its more like hints.
However, I do feel that it is almost near a full coding.

try to fill in the blanks for the rest.

Every control in ASP.NET has a property called AutoPostBack.
AutoPostBack is functioned like a button''s click event.
If there is any changes made to control, it will carry out a postback event.
Next, the ASP.NET control need a action event for you to handle in code behind.
In your case, you need the CheckBoxList''s SelectedIndexChanged action event.

Example of coding in ASP.NET page:
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"

    onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
</asp:CheckBoxList>



这将处理所选索引更改的回发事件:


This will handle the postback event of selected index changed:

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
    // Do something
}





代码背后的编码示例



Example of coding in code behind

protected void Page_Load(object sender, EventArgs e)
{
    CheckBoxList1.AutoPostBack = true;
    CheckBoxList1.SelectedIndexChanged += new EventHandler(CheckBoxList1_SelectedIndexChanged);
}

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
    // Do something
}


这篇关于如何在不使用asp.net中的按钮的情况下在列表框中显示checkboxlist值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆