I have a CheckBoxList
which is bound by an SqlDataSource
control. I want to remove some items from that list according to some conditions when the page loads.
Asked
Active
Viewed 365 times
-1

Dmitry Bychenko
- 180,369
- 20
- 160
- 215

Khushali bhangde
- 1
- 1
2 Answers
1
Multiple options:
- change the
SelectCommand
accordingly - use
cbl.Items.Remove(item)
orcbl.Items.RemoveAt(index)

Tim Schmelter
- 450,073
- 74
- 686
- 939
-
I tried the second option (cbl.Items.Remove(item)). But somehow it is not working. The items are still there. Where do I add that code? I had added it in the Page_Load function. – Khushali bhangde Feb 17 '16 at 17:24
0
Your SqlDataSource should have a selectCommand which references parameters:
SELECT * FROM [tag] where ([name] like @nameFilter)
You can then set the values for those parameters:
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource1.SelectParameters.Add("nameFilter", "value");
FormView1.DataBind();
}

CamW
- 3,223
- 24
- 34