• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 814
  • Last Modified:

Bind visible control in gridview

hey guys i need to set a control in a gridview visible  to true or false if the text is Yes or No

if binding value is Yes the the visible must be true
  • 2
1 Solution
Code behind is best for this.  I'm a VB person so this might not be EXACTLY right :0)

    protected void myGvRowDataBound(object sender, GridViewRowEventArgs e) {
        switch (e.Row.RowType) {
            case DataControlRowType.DataRow:
                Label myControl = e.row.findcontrol("myControlIDHere");
                if (Convert.ToBoolean(e.row.dataitem("myDataBaseColumn"))) {
                    myControl.Visible = false;

Open in new window

JCWEBHOSTAuthor Commented:
i am looking for something like this

<%# ConvertBoolToYesNo(Eval("YOUR_FIELD"))%>
That's what my code is doing.

You cannot do your approach in-line because the ID value of the DIV and IMAGE will change for every row, so you get javascript errors.  The code behind method is the cleanest and most reliable way to work with the correct ID values for each row.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now