GridView and Eval

I am trying to pass a value through an Eval in my GridView, but instead of passing the actual value, it passes the string "<% # Eval, etc.". This is my code, can anyone advise?

enter code here<asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="btnUpload" OnClientClick="loadDialog('<%# Eval(PK_SpecialEvent).ToString() %>') " Text="Upload/Open Files" runat="server"  />
            </ItemTemplate>
        </asp:TemplateField>
+3
source share
2 answers

Try the following:

OnClientClick='<%# Eval("PK_SpecialEvent", "loadDialog(\"{0}\");") %>'

Another, more readable way is to do this in code. Good place in the GridView RowDataBound Event .

+2
source

I only did GridView once before I started using ASP.NET, but should: -

Eval(PK_SpecialEvent).ToString()

added quotes to become similar:

Eval("PK_SpecialEvent").ToString()

At least - it works in my working GridView code.

-2
source

All Articles