Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 811
  • 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
0
JCWEBHOST
Asked:
JCWEBHOST
  • 2
1 Solution
 
RouchieCommented:
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;
                }
                break;
        }
    }

Open in new window

0
 
JCWEBHOSTAuthor Commented:
i am looking for something like this

<%# ConvertBoolToYesNo(Eval("YOUR_FIELD"))%>
0
 
RouchieCommented:
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.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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