111,126
社区成员
发帖
与我相关
我的任务
分享this.Label1.Text = this.RadioButtonList1.SelectedValue;
this.Label3.Text = "";
for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
{
if (this.CheckBoxList1.Items[i].Selected == true)
{
this.Label3.Text += this.CheckBoxList1.Items[i].Value + "|";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string ss="";
GetCheckedinfo(CheckBoxList1,ref ss);
GetCheckedinfo(CheckBoxList2, ref ss);
GetCheckedinfo(this.RadioButtonList1, ref ss);
this.Label1.Text = ss;
}
private void GetCheckedinfo(ListControl mycontrol,ref string ss)
{
int count = mycontrol.Items.Count;
for (int i = 0; i < count; i++)
{
if (mycontrol.Items[i].Selected)
{
ss += mycontrol.Items[i].Value + "|";
}
}
}
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
private string ss = "";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
ListControl mycontrol = (ListControl)sender;
for (int i = 0; i < mycontrol.Items.Count; i++)
{
if (mycontrol.Items[i].Selected == true)
{
ss += mycontrol.Items[i].Value + "|";
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.Text = ss;
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem>111</asp:ListItem>
<asp:ListItem>222</asp:ListItem>
<asp:ListItem>333</asp:ListItem>
<asp:ListItem>444</asp:ListItem>
<asp:ListItem>555</asp:ListItem>
<asp:ListItem>666</asp:ListItem>
</asp:CheckBoxList>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:CheckBoxList ID="CheckBoxList2" runat="server" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem>2111</asp:ListItem>
<asp:ListItem>2222</asp:ListItem>
<asp:ListItem>2333</asp:ListItem>
<asp:ListItem>2444</asp:ListItem>
<asp:ListItem>2555</asp:ListItem>
<asp:ListItem>2666</asp:ListItem>
</asp:CheckBoxList>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem>222</asp:ListItem>
<asp:ListItem>333</asp:ListItem>
<asp:ListItem>444</asp:ListItem>
<asp:ListItem>555</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
ListControl mycontrol = (ListControl)sender;
string ss = "";
for (int i = 0; i < mycontrol.Items.Count; i++)
{
if (mycontrol.Items[i].Selected == true)
{
ss += mycontrol.Items[i].Value + "|";
}
}
this.Label1.Text = ss;
}
}