Gaslight Deceive Subvert
Gaslight Deceive Subvert

Reputation: 20382

Get the this object using eval in a gridview in asp

I can't find any answer anywhere. I want to refer to the row object itself in an databinding expression in a gridview, like this:

<asp:TemplateField HeaderText="Description">
    <ItemTemplate>
        <asp:Label runat="server" 
                   Text = '<%# GetPendingReason(Eval("this")) %>' />                                    
    </ItemTemplate>
</asp:TemplateField>

But it doesn't work because "this" doesn't refer to any attribute. Referencing individual attributes works fine, but how do you refer to the current row?

Upvotes: 2

Views: 2616

Answers (2)

Lawrence Johnson
Lawrence Johnson

Reputation: 101

Simply use <%# Container.DataItem %>. Do not use Databinder.

Upvotes: 10

Saanch
Saanch

Reputation: 1844

If you want to refer to the current row you do that at codebehind using

GridViewRow row = GridView1.Rows[index];
at any of the GridView event.

Upvotes: 1

Related Questions