checkboxlist(list copy)

admin 265 0

大家好,今天给各位分享checkboxlist的一些知识,其中也会对list copy进行解释,文章篇幅可能偏长,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在就马上开始吧!

一、CheckBox和CheckBoxList有什么区别

1、楼主应该说错了吧,应该是CheckBox和CheckListBox。

2、CheckBoxshi复选框,用户可以通过CheckBox指示某个特定条件是处于打开状态还是关闭状态,它常用于为用户提供是/否真/假

3、选项,因为CheckBox彼此是独立工作,所以用户可以同时选择一个或多个CheckBox。

4、CheckListBox控件几乎具有ListBox控件的所有功能,它可以看做每项都是CheckBox控件的ListBox,在应用程序中,CheckListBox控件用于提供一组并列的可选项。

二、asp.net 获取checkboxlist值

1、通过JS来获取值,首先在checkbox生成的时候记得给他的Text赋一个标识值比如ID之类的,然后给他一个 onclick客户端方法用来获取他的值然后放在一个页面的隐藏控件中即可。

2、当你选择了checkbox的时候把值存到隐藏控件,后台就可以直接访问隐藏控件中的值了。你存放隐藏控件的时候记得每个值之间用个分隔符隔开,

三、5、 Checkbox控件与Checkboxlist控件有什么区别

Checkboxlist:创建多项选择复选框组,该复选框组可以通过将控件绑定到数据源动态创建。

CheckBoxList控件提供可以通过数据绑定动态生成的多项选择复选框组。它包含一个 Items集合,集合中的成员与列表中的各项相对应。若要确定选中了哪些项,请循环访问该集合并测试列表中每一项的 Selected属性。

可以通过使用 RepeatLayout和 RepeatDirection属性指定列表的显示方式。如果将 RepeatLayout设置为 RepeatLayout.Table(默认设置),则列表将呈现在表中。如果将其设置为 RepeatLayout.Flow,则列表将以不具有任何表结构的方式呈现。默认情况下,RepeatDirection设置为 RepeatDirection.Vertical。将该属性设置为 RepeatDirection.Horizontal时,列表将水平呈现。

CheckBoxList控件提供方便的数据绑定功能。然而,单个的 CheckBox控件可提供对布局的更多控制。

<%@ Page Language="C#" AutoEventWireup="True"%>

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<title> CheckBoxList Example</title>

void Check_Clicked(Object sender, EventArgs e)

Message.Text="Selected Item(s):<br/><br/>";

// Iterate through the Items collection of the CheckBoxList

// control and display the selected items.

for(int i=0; i<checkboxlist1.Items.Count; i++)

if(checkboxlist1.Items[i].Selected)

Message.Text+= checkboxlist1.Items[i].Text+"<br/>";

<form id="form1" runat="server">

<h3> CheckBoxList Example</h3>

Select items from the CheckBoxList.

<asp:CheckBoxList id="checkboxlist1"

OnSelectedIndexChanged="Check_Clicked"

<asp:ListItem>Item 1</asp:ListItem>

<asp:ListItem>Item 2</asp:ListItem>

<asp:ListItem>Item 3</asp:ListItem>

<asp:ListItem>Item 4</asp:ListItem>

<asp:ListItem>Item 5</asp:ListItem>

<asp:ListItem>Item 6</asp:ListItem>

<asp:label id="Message" runat="server" AssociatedControlID="checkboxlist1"/>

使用 CheckBox控件可以允许用户选择 true状态或 false状态。

<%@ Page Language="C#" AutoEventWireup="True"%>

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<title>CheckBox CheckedChanged Example</title>

void Check_Clicked(Object sender, EventArgs e)

// Calculate the subtotal and display the result in currency format.

// Include tax if the check box is selected.

Message.Text= CalculateTotal(checkbox1.Checked).ToString("c");

void Page_Load(Object sender, EventArgs e)

// Display the subtotal without tax when the page is first loaded.

// Calculate the subtotal and display the result in currency format.

Message.Text= CalculateTotal(false).ToString("c");

double CalculateTotal(bool Taxable)

// Calculate the subtotal for the example.

double Result= 1.99+ 2.99+ 3.99;

<form id="form1" runat="server">

<h3>CheckBox CheckedChanged Example</h3>

Select whether to include tax in the subtotal.

<table border="1" cellpadding="5">

<asp:Label id="Message" runat="server"/>

<asp:CheckBox id="checkbox1" runat="server"

Text="Include 8.6% sales tax"

OnCheckedChanged="Check_Clicked"/>

四、C#ASP.NET 如何判断CheckBoxList没有一项是被选中的

1、文章类型:<asp:DropDownList ID="DDLtype" runat="server">

2、<asp:ListItem Text="--选择类型--" Value=""></asp:ListItem>

3、<asp:ListItem Text="酒店酒楼" Value="酒店酒楼"></asp:ListItem>

4、<asp:ListItem Text="火锅" Value="火锅"></asp:ListItem>

5、<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="选择文章类型" ClientValidationFunction="ClientValidate" ControlToValidate="DDLtype" ValidateEmptyText="True"></asp:CustomValidator>

6、<script language="javascript" type="text/javascript">

7、function ClientValidate(source, arguments){

8、arguments.IsValid= document.getElementsByTagName("select")[0].selectedIndex> 0? true: false;

9、<asp:ListItem Text="--选择类型--" Value=""></asp:ListItem>

10、在第一行加上自定义的一行,然后判断,如果选择的是第一行则表示没有选中,还可以起到提示作用

11、这样一来就可以用asp:CustomValidator自定义的验证控件进行客户端验证

12、验证的JS代码也写在下面了,自己可以看一下

关于checkboxlist和list copy的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。