Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp.net repeater

Status
Not open for further replies.

cmn2

Programmer
Mar 6, 2003
73
US
Hello
I rarely work with asp.net and find I'm snagged on something that should be simple. Can someone help me clean up this if statement so I can single out one dataitem that I wish to color differently. The error I'm getting says that an expression is expected where I have entered
<%#Container.DataItem("department").toString = "Finance" %>.
Thank you for any help or direction you can provide.

Here is my code...
<asp:Repeater id="DepartmentsRepeater" runat="server">
<ItemTemplate>
<% if <%#Container.DataItem("department").toString = "Finance" %> then %>
<asp:HyperLink ForeColor="black" Text='<%# DataBinder.Eval(Container.DataItem, "department") %>' NavigateUrl='<%# "/Departments/" + DataBinder.Eval(Container.DataItem,"department").ToString() + "/index.asp" %>' runat="server" /><BR>
<%else%>
<asp:HyperLink ForeColor="gray" Text='<%# DataBinder.Eval(Container.DataItem, "department") %>' NavigateUrl='<%# "/Departments/" + DataBinder.Eval(Container.DataItem,"department").ToString() + "/index.asp" %>' runat="server" /><BR>
<%end if%>
</ItemTemplate>
</asp:Repeater>
 
What you are trying to do looks like classic ASP programming. Remove that statement and use the code behind page for this. There is an ItemDataBound event for the Repeater control. Use this event and check the value in there, and then change the color accordingly.

Jim
 
Here is one for a datagrid or repeater:

Protected Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
CType(e.Item.FindControl("HyperLink1"), HyperLink).NavigateUrl = "/departments/" & DataBinder.Eval(e.Item.DataItem, "department")
CType(e.Item.FindControl("HyperLink1"), HyperLink).Text = DataBinder.Eval(e.Item.DataItem, "department")
End If
end sub

Give your Hyperlinks and other server controls in the repeater or datagrid an ID.
Check for Nulls in the data.


 
Thanks for the help. I was clearly going about this the wrong way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top