-1

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.

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

2 Answers2

1

Multiple options:

  1. change the SelectCommand accordingly
  2. use cbl.Items.Remove(item) or cbl.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