Hi,
I'm working on a grid for our website and I'm trying to set up the DataItemTemplate for one particular column that can be hyperlinked depending on a value in another column.
<dx:GridViewDataTextColumn Caption="Loc" FieldName="PATH_NAME">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Loc Ref" FieldName="ITEM_ID">
<DataItemTemplate>
## if (<% Eval("PATH_NAME") %> == 'CYCLOPS") {
'<a href="javascript:View(' + <% Eval("ITEM_ID") %> +');"><% Eval("Item_ID") %></a>'
} else {
<% Eval("ITEM_ID") %>
} ##
</DataItemTemplate>
</dx:GridViewDataTextColumn>So, of course this doesn't work, but the intent is to evaluate the value in the "PATH_NAME" column and if the text is equal to "CYCLOPS", the data template should make the cell in the Loc Ref column for that row into a hyperlink. If the PATH_NAME is anything else, then simply output the item_id
Like I said, it doesn't work as expected, I get the whole bundle (if statements, braces and all) in the cell.
Is there a way to specify that conditional rendering in the ASPx code? If not, can you give an example of how to specify it in the code behind (the documentation on that is a little jumbled)?
I tried adjusting the code to:
<dx:GridViewDataTextColumn Caption="Loc" FieldName="PATH_NAME"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn Caption="Loc Ref" FieldName="ITEM_ID"> <DataItemTemplate> <% if Eval("PATH_NAME") = "CYCLOPS" Then Response.Write("<a href=""javascript:View('") Eval("ITEM_ID") Response.Write("');"">") Eval("ITEM_ID") Response.Write("</a>") Else Eval("ITEM_ID") End If %> </DataItemTemplate> </dx:GridViewDataTextColumn>
But it didn't like that either. Eval needs to be part of a bound data element.
Hello,
Thank you for contacting us. We need some additional time to review this scenario to provide you with a precise answer.
We appreciate your patience while we are working on finding a solution to your inquiry.