Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Need some help here as to how to bind a text eval value properly in a gridview.

Please see code below.

ASP.NET
 <asp:TemplateField HeaderText="Rate" Visible="True">
                    <ItemTemplate>
                       
                        <asp:Label ID="lblRate" runat="server"
Text='<%#GetLabelText(Eval("platinumRate"), Eval("goldRate"), Eval("silverRate"))%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>


code behind is:

C#
public string GetLabelText(Object platinumRate, Object goldRate, Object silverRate)
       {
           if (DropDownList1.SelectedValue == "Platinum")
           {
               return DataBinder.Eval(platinumRate,"platinumRate").ToString();
           }
           else if (DropDownList1.SelectedValue == "Gold")
           {
               return DataBinder.Eval(goldRate, "goldRate").ToString();
           }
           else
           {
               return DataBinder.Eval(silverRate, "silverRate").ToString();
           }

       }


At the moment I get the error:

DataBinding: 'System.Decimal' does not contain a property with the name 'platinumRate'.

Please help if you can.

Regards
Posted
Comments
sahabiswarup 18-Jan-12 2:18am    
did you check properly there is a field named platinumRate in your database
Andrew Chambers 18-Jan-12 2:21am    
yes indeed

1 solution

the only thing that i can think of are:
1. wrong field name in your select query
2. datafield in gridview and fields in your datasource mismatch
3. case sensitive?
4. type mismatch?

more likely its field mismatch like typo error.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900