0

I'm using a gridview to display some data. There is an image button to display a flag. Within the GridView RowDataBound Event i'm changing the visibility of that button. But the visibility didn't get changed. Here is the code:

bool status = true; // getting this via dataset
ImageButton imgTest = (ImageButton)e.Row.FindControl("ImageButton1");
imgTest.Visible = status;

But still visibility is false.

EDIT:

Here is my HTML Code;

<asp:GridView runat="server" ID="gvScheduleView" DataKeyNames="ControlID,IsPrinted, PrintDate, DueDate"
            Width="100%" ShowHeader="true" ShowFooter="true" AutoGenerateColumns="false"
            OnRowDataBound="gvScheduleView_rowDataBound" Height="100%" CssClass="removePaddingRight">
            <Columns>
                <asp:TemplateField HeaderText="Type" HeaderStyle-HorizontalAlign="center" ItemStyle-HorizontalAlign="Center">
                    <ItemTemplate>
                        <%# Eval("Type") %>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Name" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="120">
                    <ItemTemplate>
                        <%# Eval("Name") %>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="&nbsp;&nbsp;Actions" HeaderStyle-HorizontalAlign="Center"
                    ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center">
                    <ItemTemplate>
                        <div style="text-align: center;">
                            <table style="margin-left: 28px;">
                                <tr style="text-align: center;">
                                    <td style="width: 20px">
                                        <asp:ImageButton ID="ibDelete" runat="server" ImageUrl="~/common/images/delete.gif"
                                            OnClick="ibDelete_click" OnClientClick="return confirm('Are you sure you wish to delete this schedule?');"
                                            CommandArgument='<%# Eval("ControlID") %>' ToolTip="Delete Schedule" />
                                    </td>
                                    <td style="width: 20px">
                                        <asp:ImageButton ID="ibRollback" runat="server" ImageUrl="~/common/images/icons/arrow_undo.png"
                                            OnClick="ibRollback_click" CommandArgument='<%# Eval("ControlID") %>' ToolTip="Rollback print generation"
                                            OnClientClick="return confirm('Are you sure you wish to rollback this schedule?');" />
                                    </td>
                                    <td style="width: 20px">
                                        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/common/images/icons/email_go.png"
                                            OnClick="ibGenerate_click" CommandArgument='<%# Eval("ControlID") %>' />
                                        <asp:Image ImageUrl="~/common/images/icons/cancel.png" ID="imInfo" runat="server"
                                            Visible="false" ToolTip="DUE DATE IS INVALID - Please change to a future date" />
                                    </td>
                                    <td style="width: 20px">
                                        <asp:ImageButton ID="ibEditProps" runat="server" ImageUrl="~/common/images/icons/building_edit.png"
                                            OnClick="ibEditProps_click" CommandArgument='<%# Eval("ControlID") %>' CommandName='<%# Eval("Type") %>'
                                            ToolTip="Edit Properties" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
Aruna
  • 1,962
  • 4
  • 25
  • 50

1 Answers1

0
<div id="DivBtnImgCopy" runat="server" visible = "<% =ShowHideButton() %>">

<asp:ImageButton ID="ibEditProps" runat="server"ImageUrl="~/common/images/icons/building_edit.png"
OnClick="ibEditProps_click"CommandArgument='<%# Eval("ControlID") %>' CommandName='<%# Eval("Type") %>'  ToolTip="Edit Properties" />

</div>

Code Behind

protected bool ShowHideButton()
    {
        bool bStatus = false;
        try
        {
            if (sCondition == "false")
            {
                bStatus = false;
            }
            else if (sCondition == "true")
            {
                bStatus = true;
            }
            return bStatus;
        }
        catch { }
    }         
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115