你的意思是不是
根据对CheckBoxList的钩选 然后根据CheckBoxList的值 来做sql 的where ??如是 你可以先
得到CheckBoxList选了哪些值 然后根据 值生成sql 的 where
<form id="form1" runat="server">
<div>
</div>
<asp:CheckBoxList ID="s_taste" runat="server" Width="253px">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="height: 26px"
Text="Button" />
</form>c# protected void Button1_Click(object sender, EventArgs e)
{
string sql = "select * from user";
int a=0;
for (int i = 0; i < s_taste.Items.Count; i++)
{
if (s_taste.Items[i].Selected == true)
{
a++;
if (a==1)
{
sql += " where ";
}
if (a > 1)
{
sql += " or ";
}
sql += " id=" + s_taste.Items[i].Value; } }
Response.Write(sql);
}
根据对CheckBoxList的钩选 然后根据CheckBoxList的值 来做sql 的where ??如是 你可以先
得到CheckBoxList选了哪些值 然后根据 值生成sql 的 where
<form id="form1" runat="server">
<div>
</div>
<asp:CheckBoxList ID="s_taste" runat="server" Width="253px">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="height: 26px"
Text="Button" />
</form>c# protected void Button1_Click(object sender, EventArgs e)
{
string sql = "select * from user";
int a=0;
for (int i = 0; i < s_taste.Items.Count; i++)
{
if (s_taste.Items[i].Selected == true)
{
a++;
if (a==1)
{
sql += " where ";
}
if (a > 1)
{
sql += " or ";
}
sql += " id=" + s_taste.Items[i].Value; } }
Response.Write(sql);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货