When data is bound to the ddl control, I want to hide or possibly ignore the items that are 1.25, 1.75 and so on. I do not want to hard code and I would like to do that dynamically so that when new values are available in the source collection it works just
the same way without any change to the system.
When data is bound to the ddl control, I want to hide or possibly ignore the items that are 1.25, 1.75 and so on. I do not want to hard code and I would like to do that dynamically so that when new values are available in the source collection it works just
the same way without any change to the system.
After binding the data you can use FindByText method to find particular list items in dropdownlist and then remove the value from dropdownlist
protected void Page_Load(object sender, EventArgs e)
{
//Ensure that you are using this code after the binding dropdwonlist with data
ListItem removeListItem = DropDownList6.Items.FindByText("1.75");
DropDownList6.Items.Remove(removeListItem);
ListItem removeListItem1 = DropDownList6.Items.FindByText("2.75");
DropDownList6.Items.Remove(removeListItem1);
}
Thanks for your reply. I do not want to hard code the values. I want to know if there is a way to
dynamically determine if it is a quarter value and then hide/remove it from the list at bind.
When data is bound to the ddl control, I want to hide or possibly ignore the items that are 1.25, 1.75 and so on.
How are you planning on defining which items should and should not be hidden? If there is a specific rule (i.e. it ends with "5" or something) then you could programatically use LINQ to only populate your DataSource attribute with those values :
// Determine which data to show
var data = GetYourNumbersHere();
if(ShouldFilter)
{
// This is a very basic example to demonstrate filtering
data = data.Where(d => d.ToString().EndsWith("5"));
}
YourDropDown.DataSource = data;
YourDropDown.DataBind();
AaravorAaradhana
I would like to do that dynamically so that when new values are available in the source collection it works just the same way without any change to the system.
If you are expecting your data source to change frequently and want to update the list based off of that, then you are likely going to need to rebind your list every time that your page is posted back :
Member
1 Points
8 Posts
Dropdown list
Feb 21, 2017 07:52 PM|AaravorAaradhana|LINK
I have a collection with following values that is bound to a drop down list.
1.00, 1.25, 1.50, 1.75, 2.00, 2.25, 2.50, 2.75, 3.001 3.25, 3.50, 3.75, 4.00…so on
When data is bound to the ddl control, I want to hide or possibly ignore the items that are 1.25, 1.75 and so on. I do not want to hard code and I would like to do that dynamically so that when new values are available in the source collection it works just the same way without any change to the system.
How can I achieve that?
Thanks.
All-Star
50831 Points
9895 Posts
Re: Dropdown list
Feb 21, 2017 08:22 PM|A2H|LINK
After binding the data you can use FindByText method to find particular list items in dropdownlist and then remove the value from dropdownlist
Aje
My Blog | Dotnet Funda
Member
1 Points
8 Posts
Re: Dropdown list
Feb 21, 2017 08:28 PM|AaravorAaradhana|LINK
Hi,
Thanks for your reply. I do not want to hard code the values. I want to know if there is a way to dynamically determine if it is a quarter value and then hide/remove it from the list at bind.
Thanks.
All-Star
50831 Points
9895 Posts
Re: Dropdown list
Feb 21, 2017 08:36 PM|A2H|LINK
From above list what all values are expected to bind to dropdownlist if we remove the quarter values
Aje
My Blog | Dotnet Funda
Member
1 Points
8 Posts
Re: Dropdown list
Feb 21, 2017 08:57 PM|AaravorAaradhana|LINK
Allowed values that can bind..It just that the quarters that should be ignored.
1.00, 1.50, 2.00, 2.50, 3.00, 3.50, 4.00..and so on
All-Star
114593 Points
18503 Posts
MVP
Re: Dropdown list
Feb 21, 2017 08:57 PM|Rion Williams|LINK
How are you planning on defining which items should and should not be hidden? If there is a specific rule (i.e. it ends with "5" or something) then you could programatically use LINQ to only populate your DataSource attribute with those values :
If you are expecting your data source to change frequently and want to update the list based off of that, then you are likely going to need to rebind your list every time that your page is posted back :
Member
1 Points
8 Posts
Re: Dropdown list
Feb 21, 2017 09:26 PM|AaravorAaradhana|LINK
Thanks. The first one did the trick.