Bind visible control in gridview

Posted on 2012-09-20
Last Modified: 2012-09-21
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
Question by:JCWEBHOST
    LVL 25

    Expert Comment

    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


    Author Comment

    i am looking for something like this

    <%# ConvertBoolToYesNo(Eval("YOUR_FIELD"))%>
    LVL 25

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now