复选框和标签 [英] Check Boxes & Labels

查看:89
本文介绍了复选框和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

谢谢您对以前的帖子的帮助!

我已经创建了一个用于员工分配的页面(设备和软件)

我有一个复选框列表,该列表通过向导连接到我的数据库表(DeviceType)之一,该表显示了Laptop,Phone,Monitor e.t.c.

我想在右侧放置标签.但是将它们隐藏起来直到选中一个框.

http://i1145.photobucket .com/albums/o506/MConnolly1991/Capture-4.png?t = 1345020789 [

Hey Guys!

Thanks for the help of previous posts by the way!

I''ve created a page for employee assignment (equipment & software)

I have a checkbox list that''s connected through the wizard to one of my database tables (DeviceType) which brings up Laptop,Phone,Monitor e.t.c.

I want to place labels on the right hand side. But hide them until a box is ticked.

http://i1145.photobucket.com/albums/o506/MConnolly1991/Capture-4.png?t=1345020789[^]

^^ Is an image of my check box and 2 labels, as you can see. Both say monitor. I''f I check Laptop though, they stay as Monitor, how do I change the second one to Laptop, and if I add a third that it''ll change to that choice and so on and so forth?

This is my first time to use check boxes and databases with labels so it''s tough enough.

Thanks in advance guys!

Mark

推荐答案

您是否有任何理由使用多个标签盒?

只需一个即可达到相同的效果.

只需在设计器"视图中将CheckBoxList的"AutoPostBack"值设置为"True",然后使用以下命令:

Is there any reason you''re using multiple label boxes?

The same effect can be achieved with a single one.

Simply set the "AutoPostBack" value of the CheckBoxList to "True" in the "Designer" view, and use the following:

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
            string selectedItems = "";
            for (int j = 0; j < CheckBoxList1.Items.Count; j++)
            {
                if (CheckBoxList1.Items[j].Selected)
                {
                    if (selectedItems.Length == 0)
                    {
                        selectedItems = CheckBoxList1.Items[j].Text;
                    }
                    else
                    {
                        selectedItems += ", " + CheckBoxList1.Items[j].Text;
                    }
                }
            }
            Label1.Text = selectedItems;
        }




您可以在客户端&服务器端.

使用JavaScript的客户端
Hi,

You can do it in both Client Side & Server Side.

Client Side using JavaScript
<asp:checkbox id="CheckBoxID" runat="server" onclick="CheckBoxChecked(this)" xmlns:asp="#unknown" />


function CheckBoxChecked(value) {
    if(value.checked == true)
       document.getElementById("<%=LabelId.ClientID %>").style.display = 'none';
    else
       document.getElementById("<%=LabelId.ClientID %>").style.display = 'block' ; 
}


服务器端事件


Server Side Event

<asp:checkbox id="CheckBoxID" runat="server" oncheckedchanged="CheckBoxChanged" xmlns:asp="#unknown" />


void CheckBoxChanged(object sender, EventArgs e)  
{  
    LabelID.Visible = false;  
}



快乐编码:)



Happy Coding :)


这篇关于复选框和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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