Reputation: 583
What I want to do is assign an ID to a table row with value of a ID of the column in question.
To clarify. I have a data table with fields [ID]
[Name]
[Description]
, and populate the ListView
like this: (I've simplified the code here for clarity)
<asp:ListView ID="MainList" runat="server" DataKeyNames="id">
<layouttemplate>
<dl id="header">
<dd class="rowHeader">Name</dd>
<dd class="rowHeader">Description</dd>
</dl>
<asp:Panel runat="server" ID="itemPlaceholder">
</asp:Panel>
</layouttemplate>
<itemtemplate>
<dl class="row">
<dd><%# Eval("name")%></dd>
<dd><%# Eval("description")%></dd>
</dl>
</itemtemplate>
</asp:ListView>
Now, what I tried was to add it like this.
<dl class="row" id='<%# Eval("id")%>'>
and of course it worked, but I need to pass it as a variable because i need to check for something with it. Like so:
<% Dim id as Integer = Eval("id") %>
<dl class="row" id='<%=id %>'>
I got this error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
And I get it why... the reason why I need this is so I can compare id with a session variable and change rows class accordingly.
Any way to go around this?
Upvotes: 0
Views: 621
Reputation: 4379
You should be able to do the same type of logic in your class attribute:
<dl class="row" id='<%# Eval("id")%>' class='<%= Eval("id") == Session["myValue"] ? "someCssClass" : "otherCssClass" %>'>
I think this should work.
Upvotes: 1