Reputation: 429
I am trying to bind Panel.visible to be visible depending on matching database table field and querystring as:
<asp:Panel ID="Panel2" runat="server" Visible='<%# Eval("Mjr_Id") == Request.QueryString["Mjr_Id"] %>'> ... </asp:Panel>
But it failed, do you have idea about the correct binding format to do this?
Upvotes: 0
Views: 582
Reputation: 31198
The Eval function returns an object, whereas the QueryString indexer returns a string. Applying the equality operator to an object and a string will result in a reference comparison, whereas you want a value comparison.
To make the code work, you'll need to convert the object to a string:
Visible='<%# Eval("Mjr_Id", "{0}") == Request.QueryString["Mjr_Id"] %>'
NB: This will perform a case-sensitive ordinal comparison. If that's not what you want, you'll need to use the string.Equals(string, string, StringComparison) method.
Upvotes: 1