2017-09-26 65 views
0
<div class="checkboxData"> 
    <asp:CheckBoxList ID="cblStrength" Class="checkBoxFilter" runat="server" DataTextField="language" OnSelectedIndexChanged="cblStrength_SelectedIndexChanged" 
    DataValueField="language" RepeatLayout="OrderedList" Width="432px"> 
    </asp:CheckBoxList> 
</div> 

上面的代碼是我的Checkboxlist。這CheckBoxList的值被動態地從數據庫綁定複選框值到數據庫加載gridTable

DataSet dsFilterItems = new DataSet(); 

CheckBoxList cblStrength = (CheckBoxList)Master.FindControl("cblStrength"); 
CheckBoxList cblForm = (CheckBoxList)Master.FindControl("cblForm"); 
CheckBoxList cblSize = (CheckBoxList)Master.FindControl("cblSize"); 

dsFilterItems = itemsBL.GetItemsForFilter(null, null, strkeywords, null, null, custRole); 

if (dsFilterItems.Tables.Count >= 0) 
{ 

    //cblStrength.Controls.Add(new LiteralControl("<br />")); 
    cblStrength.DataSource = dsFilterItems.Tables[0]; 
    cblStrength.DataTextField = "Strength"; 
    cblStrength.DataValueField = "Strength"; 
    cblStrength.DataBind(); 

    //cblForm.Controls.Add(new LiteralControl("<br />")); 
    cblForm.DataSource = dsFilterItems.Tables[1]; 
    cblForm.DataTextField = "itemForm"; 
    cblForm.DataValueField = "itemForm"; 
    cblForm.DataBind(); 

    //cblSize.Controls.Add(new LiteralControl("<br />")); 
    cblSize.DataSource = dsFilterItems.Tables[2]; 
    cblSize.DataTextField = "CF_Size"; 
    cblSize.DataValueField = "CF_Size"; 
    cblSize.DataBind(); 
} 

複選框值動態加載基於搜索的約束......

現在我只顯示覆選框在DataGrid檢查的值,我有查詢從數據庫中選擇其中如下所示

SELECT * FROM Items WHERE Strength IN (@cblStrength) 

但它只能單個複選框值我應該爲多項選擇,以及如何負載的DataGrid做不清爽。

回答

0

您必須連接sql查詢才能使多個/逗號分隔參數起作用。例如。

Set @query = 'SELECT * FROM Items WHERE Strength IN ('[email protected]+')'; 
EXEC sp_executesql @query; 

快樂編碼!