Hi
I have a repeater. I want if value of a particular column say 10 is 1 , i want to highlight column 2 of that row
Thanks
Hi
I have a repeater. I want if value of a particular column say 10 is 1 , i want to highlight column 2 of that row
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
Aravind GovindarajRank #430 · 5.8K reputationPosted May 31, 2023, 3:58 PM EDT
Please find the code snippet for the same
protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Assuming your data item is a DataRowView DataRowView dataItem = (DataRowView)e.Item.DataItem; // Assuming your column 10 is an integer column int column10Value = Convert.ToInt32(dataItem["Column10"]); // Assuming column 2 is a Label control in the Repeater Label column2Label = (Label)e.Item.FindControl("Column2Label"); if (column10Value == 1) { // Apply the desired formatting to highlight column 2 column2Label.BackColor = System.Drawing.Color.Yellow; // You can modify other properties like ForeColor, Font, etc. as needed } } }Prasad RaveendranRank #320 · 7.8K reputationPosted May 31, 2023, 2:59 PM EDT
To highlight a column in a repeater control based on its value, you can use a conditional statement in the markup or code-behind of the repeater control. Here's an example using ASP.NET Web Forms:
Define your repeater control in the markup:
In the code-behind, define the HighlightColumn method to conditionally set the CSS class for the column based on its value:
protected string HighlightColumn(object columnValue) { string cssClass = ""; // Set the desired condition for highlighting if (columnValue != null && columnValue.ToString() == "SomeValue") { cssClass = "highlighted-column"; } return $"class='{cssClass}'"; }Define the CSS class in your stylesheet:
.highlighted-column { background-color: yellow; /* Add any other styles for highlighting here */ }In this example, the HighlightColumn method checks the value of the column and returns a CSS class attribute that includes the class name "highlighted-column" if the condition is met. The CSS class defines the styles for highlighting the column, such as setting the background color to yellow. Adjust the condition and CSS styles according to your specific requirements.
Remember to bind your repeater control to the data source and call the appropriate method to populate the repeater before rendering the page.