1:
bool flag = false;
foreach(ListItem item in this.ListBox1.Items)
{
if(item.Text == this.label1.Text)
{
flag = true;
break;
}
} if(flag)
{
s1:
}
else
{
s2;
}
bool flag = false;
foreach(ListItem item in this.ListBox1.Items)
{
if(item.Text == this.label1.Text)
{
flag = true;
break;
}
} if(flag)
{
s1:
}
else
{
s2;
}
如果不是,就循环ListBox的Item,构造sql语句
bool bExist = false;
foreach(ListItem o in this.ListBox1)
{
if(o.Selected)
{
sValue += "'"+ o.Value +"',";
}
if(o.Text.Trim() == this.TextBox1.Text.Trim())
{
bExist = true;
}
} if(bExist)
{
//×?s1
} if(sValue.Length>0)
{
sValue = sValue.Substring(0,sValue.Length-1); string strSQL =" ............. where name in("+ sValue +" )";
}
2、建立一个循环,取出其值,生成一个符合sql语法的string
for(int SourceCount = 0; SourceCount < this.LBoxSource.Items.Count; SourceCount++)
{
if(this.LBoxSource.Items[SourceCount].Selected == true)
{
if(this.LBoxTarget.Items[TargetCount].Text == this.Label1.Text)
{
执行s1;
}
else
{
执行s2;
}
}
}
2.
String StrText = "";
for(int SourceCount = 0; SourceCount < this.LBoxSource.Items.Count; SourceCount++)
{
if(this.LBoxSource.Items[SourceCount].Selected == true)
{
StrText += this.LBoxSource.Items[SourceCount].Text+",";
}
}
select id from table where xxx in (StrText.TrimEnd(','));
foreach(ListItem item in this.ListBox1.Items)
{
sql = sql + item + "AND"
}
sql = sql.substring(0. sql.length()-3);