Reputation: 2295
Ok just thinking of how to put the question right.
I have a datatable which returns some feedback details. The datatable contains feedbacks of two companies. The feedbacks of the datatable distinguished based on an indicator in the each data row.
The repeater is sorted on date order (newest first). If the companies are A and B, company A's feedback will be always listed in the top, since they are the newest. I have rendered an image and some wording to mention if the listed feedback is company B feedback.
Public Function RenderTitle(ByVal objItem As Object) As String
Select Case objItem
Case 1
Return String.Empty
Case 0
Return "Feedback below obtained whilst a member of our sister company " & "<img src=""../img/logo.png"" />"
Case Else
Return String.Empty
End Select
End Function
The title is rendered if the feedback belongs to company B.
Problem: I dont want the title to be rendered in all the items of the company B. I want it to render just in the first item (feedback) that belongs to Company B. How can I achieve this?
Upvotes: 0
Views: 323
Reputation: 1669
Formatting the contents of a DataList or Repeater control based upon the data can be accomplished by using two techniques.
The first technique is to create an event handler for the ItemDataBound event, which fires as each record in the data source is bound to a new DataListItem or RepeaterItem. In the ItemDataBound event handler, the current item's data can be examined, and then formatting can be applied to the contents of the template or, for DataListItems, to the entire item itself.
Alternatively, custom formatting can be realized through formatting functions. A formatting function is a method that can be invoked from the DataList or Repeater's templates that returns the HTML to emit in its place. Often, the HTML returned by a formatting function is determined by the values being bound to the current item. These values can be passed into the formatting function, either as scalar values or by passing-in the entire object being bound to the item (such as the ProductsRow instance).
http://msdn.microsoft.com/en-us/library/bb510136.aspx
Upvotes: 2
Reputation: 11464
Can you try something like this... (Ugly Code & Not Tested)
HTML
...
<asp:HiddenField ID="hdnIsTitleRenderd" runat="server"/>
...
CODE
Page_Load()
If Not IsPostBack
hdnIsTitleRenderd.Value = "False"
End If
End Sub
Public Function RenderTitle(ByVal objItem As Object) As String
Select Case objItem
Case 1
Return String.Empty
Case 0
If Convert.ToBoolean(hdnIsTitleRenderd.Value) = False
hdnIsTitleRenderd.Value = "True"
Return "Feedback below obtained whilst a member of our sister company " & "<img src=""../img/logo.png"" />"
Else
Return String.Empty
End If
Case Else
Return String.Empty
End Select
End Function
Upvotes: 1