Hi there,
You're mixing classic ASP techniques with ASP.NET which won't work. Your controls are built during the data binding process, and then the combined HTML for the control is injected in the page. Response.Write on the other hand writes directly to the response. So, even if this code would run, the result from Response.Write would show up at a completely different location (at the top of the page).
Instead, you need to use data binding syntax. You can use a Label or a Literal and then have code like this:
Code:
<ItemTemplate>
<asp:Literal runat="server" Text='<%# DetermineType(Eval("eventnews_type")) %>'/>
<asp:LabelID="eventnews_dateLabel"runat="server"Text='<%# Eval("eventnews_date") %>'/>
<br/>
<b><ahref=newszoom.aspx?article=<%# Eval("eventnews_id") %>><asp:LabelID="eventevent_titleLabel"runat="server"Text='<%# Eval("eventevent_title") %>'/></a></b>
<br/>
</ItemTemplate>
Then add the following method to the code behind:
Code:
Protected Function DetermineType(newsType As Object) As String
If newsType.ToString() = "event" Then
Return "Upcoming Event:"
Else
Return ""
End If
End Function
A few other comments:
1. If you post code, can you please paste it in Notepad first to remove color coding and then use the forum editor's Code toolbar button to wrap your code in code tags. Otherwise, this forum messes up the code.
2. The DataList control is considered outdated and deprecated. Instead, look at the ListView which enables you to do the same stuff, but with more flexibility.
3. Consider getting a copy of my book Beginning ASP.NET 4 in C# and
VB (or wait for the 4.5 version that should be out soon). I discuss stuff like this in great detail in that book.
Cheers,
Imar