62,046
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
string str = "go1,go2,go3,go4";
string[] items = str.Split(',');
for (int i = 0; i < items.Length; i++)
{
if (CheckBoxList2.Items.FindByText(items[i]) != null)
{
CheckBoxList2.Items.FindByText(items[i]).Selected = true;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string str = "go1,go2,go3,go4";
string[] items = str.Split(',');
foreach (ListItem li in this.CheckBoxList1.Items)
{
for (int i = 0; i < items.Length; i++)
{
if (li.Value == items[i])
{
li.Selected = 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">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Value="1" Text="CheckBox1"></asp:ListItem>
<asp:ListItem Value="2" Text="CheckBox2"></asp:ListItem>
<asp:ListItem Value="3" Text="CheckBox3"></asp:ListItem>
<asp:ListItem Value="4" Text="CheckBox4"></asp:ListItem>
<asp:ListItem Value="5" Text="CheckBox5"></asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
public partial class SelectItemByValue : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string[] str = new string[] { "1", "3", "5" };
foreach (ListItem item in this.CheckBoxList1.Items)
{
for (int i = 0; i < str.Length; i++)
{
if (item.Value == str[i])
{
item.Selected = true;
}
}
}
}
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class ceshi : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strcon = ConfigurationManager.ConnectionStrings["WHConn"].ConnectionString;
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
string strcom = "select user_name from users";
SqlCommand sqlcom = new SqlCommand(strcom, conn);
SqlDataReader sdr = sqlcom.ExecuteReader();
try
{
this.CheckBoxList1.DataSource = sdr;
this.CheckBoxList1.DataTextField = "user_name";
this.CheckBoxList1.DataValueField = "user_name";
this.CheckBoxList1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sdr.Close();
conn.Close();
conn.Dispose();
}
string str = "gootey,zf,go3,go4";
string[] items = str.Split(',');
foreach (ListItem li in this.CheckBoxList1.Items)
{
for (int i = 0; i < items.Length; i++)
{
if (li.Text == items[i])
{
li.Selected = true;
}
}
}
}
}
}
string str = "gootey,zf,go3,go4";
string[] items = str.Split(',');
for (int j = 0; j < CheckBoxList1.Items.Count; j++)
{
for (int i = 0; i < items.Length; i++)
{
if (CheckBoxList1.Items[j].Value.ToString().Trim() == items[i].ToString().Trim() )
{
CheckBoxList1.Items[j].Selected = true; }
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ceshi.aspx.cs" Inherits="ceshi" %>
<%@ Import Namespace="System.Data" %>
<!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">
<script language="javascript" src ="calendar.js" type="text/javascript" charset="gb2312"></script>
<style type="text/css">
a{TEXT-DECORATION:none}
A:link {COLOR:Black;}
A:visited{COLOR:Black;}
A:hover {COLOR: red;}
</style>
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="user_name"
DataValueField="user_name" DataMember="DefaultView" EnableTheming="True"
Height="16px"
Width="246px" BorderStyle="None" RepeatLayout="Flow">
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:WHConn %>"
SelectCommand="SELECT [user_name] FROM [users]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class ceshi : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string str = "gootey,zf,go3,go4";
string[] items = str.Split(',');
foreach (ListItem li in this.CheckBoxList1.Items)
{
for (int i = 0; i < items.Length; i++)
{
if (li.Text == items[i])
{
li.Selected = true;
}
}
}
}
}
}
string[] sort = cd.Remark.Split(',');
foreach (string item in sort)
{
for (int i = 0; i < repeater1.Controls.Count; i++)
{
CheckBox box = repeater1.Controls[i].FindControl("cb_Sort") as CheckBox;
if (item == box.Text)
{
box.Checked = true;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
string str = "go1,go2,go3,go4";
string[] items = str.Split(',');
foreach (ListItem li in this.CheckBoxList1.Items)
{
for (int i = 0; i < items.Length; i++)
{
if (li.Text==items[i])
{
li.Selected = true;
}
}
}
}
if(!this.IsPostBack)
{
SqlConnection con=new SqlConnection("server=.;database=Northwind;uid=sa;pwd=;");
con.Open();
SqlCommand cmd=new SqlCommand("select top 10 * from Employees",con);
SqlDataReader sdr=cmd.ExecuteReader();
try
{
this.chklistA.DataSource=sdr;//数据源
this.chklistA.DataTextField="";//显示的字段
this.chklistA.DataValueField="";//值的字段
this.chklistA.DataBind();//绑定
}
catch(Exception Ex)
{
throw Ex;
}
finally
{
sdr.Close();
con.Close();
con.Dispose();
}
}