0

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?

2
  • post your code ,not getting your problem Commented Oct 23, 2012 at 15:33
  • It failed: what is the error? Commented Oct 23, 2012 at 15:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.