TrN
TrN

Reputation: 1250

ASPxGridView and Eval(string) method

I'm trying to add column to ASPxGridView which would have link to other page:

  <Columns>
        ...
        <dxwgv:GridViewDataColumn Caption=" " VisibleIndex="10">
            <DataItemTemplate>
                <dxe:ASPxHyperLink ID="lnkEdit" runat="server" Text="Edit" NavigateUrl="../Category/Elements/<%# Eval("Id").ToString() %>/Edit"/>
            </DataItemTemplate>
        </dxwgv:GridViewDataColumn>
    </Columns>

But I get error:

Parser Error Message: The server tag is not well formed.

when I used ' ' instead " " the link href property is "../Category/Elements/<%# Eval("Id").ToString() %>/Edit"

Upvotes: 1

Views: 5109

Answers (1)

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107508

I don't think you can put databinding elements into the middle of the attribute value. The entire value needs to be within the <% %>:

NavigateUrl='<%# "../Category/Elements/" +  Eval("Id").ToString() + "/Edit" %>'

I'm not sure with UI library you're using, but usually the Eval() allows a string format parameter. This would be preferable to the string concatenation approach. You might be able to do:

NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "Id", "../Category/Elements/{0}/Edit") %>'

Upvotes: 3

Related Questions