复制代码 代码如下:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Value == "A" || ListBox1.Items[i].Value == "C")
{
ListBox1.Items[i].Selected = true;
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form runat="server">
<asp:ListBox runat="server" SelectionMode="Multiple">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
<asp:ListItem>E</asp:ListItem>
</asp:ListBox>
</form>
</body>
</html>
复制代码 代码如下:
<asp:TextBox runat="server"></asp:TextBox>
<br />
<asp:Button runat="server" Text="Binding" />
<br />
<br />
<asp:ListBox runat="server" SelectionMode="Multiple" ></asp:ListBox> .
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Data_Binding();
}
}
private void Data_Binding()
{
this.ListBox1.DataSource = Site();
this.ListBox1.DataTextField = "key";
this.ListBox1.DataValueField = "value";
this.ListBox1.DataBind();
}
private Dictionary<string, string> Site()
{
Dictionary<string, string> site = new Dictionary<string, string>();
site.Add("Insus.NET cnblogs", );
site.Add("Microsoft", "http://www.microsoft.com");
site.Add("Google", "http://www.google.com");
site.Add("Yahoo", "http://www.yahoo.com.cn");
site.Add("Ifeng", "http://www.ifeng.com");
site.Add("sina", );
site.Add("163", "http://www.163.com");
site.Add("QQ", "http://www.qq.com");
return site;
}
复制代码 代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string[] s = this.TextBox1.Text.Split(';');
foreach (ListItem li in this.ListBox1.Items)
{
li.Selected = ((IList)s).Contains(li.Text) ? true : false;
}
}
复制代码 代码如下:
int coun =listBox2.SelectedItems.Count;
for(;coun> =1;coun--)
{
listBox2.Items.RemoveAt(listBox2.SelectedIndices[coun-1]);
}
listBox2.ClearSelected();
}
新闻热点
疑难解答
图片精选