Hi
I want to check condition in repeater itemdatabound. If condition is not met then record should not be displayed.
Thanks
Hi
I want to check condition in repeater itemdatabound. If condition is not met then record should not be displayed.
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Apr 18, 2023, 5:18 AM EDT
To display or not to display a record in a Repeater control's ItemDataBound event based on a condition, you can simply manipulate the Visible property of the RepeaterItem object that represents the current data item being bound.
Here's a sample code that demonstrates how to achieve this:
protected void rptMyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Assuming that you have a condition that you want to check bool conditionMet = CheckCondition(e.Item.DataItem); if (!conditionMet) { // Hide the RepeaterItem if the condition is not met e.Item.Visible = false; } } }Thanks
Amit MohantyRank #112 · 20K reputationPosted Apr 18, 2023, 4:50 AM EDT
You can use the ItemDataBound event of the Repeater control to check your condition and hide the item if the condition is not met. Here's an example code snippet in C#:
protected void repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Get the data item for this repeater item DataRowView dataItem = (DataRowView)e.Item.DataItem; // Check your condition if (conditionNotMet) { // Hide the item e.Item.Visible = false; } } }