Hide Button in templatefield when status of gridview is "Full Payment"

I have 3 statuses, full payment, half payment and not paid.
If the status is full payment, the button isnt supposed to show!!
However, the button is showing even if its full payment!!
aspx
  <asp:GridView ID="gvInvoice" runat="server" CellPadding="6"  
     CssClass= "table table-striped table-bordered table-condensed" AutoGenerateColumns="False"  >
            <Columns>
                <asp:BoundField DataField="InvoiceId" HeaderText="#" ReadOnly="True" SortExpression="InvoiceId" />
                <asp:BoundField DataField="InvoiceDate" HeaderText="Date" ReadOnly="True" SortExpression="InvoiceDate" />
                <asp:BoundField DataField="InvoiceDueDate" HeaderText="DueDate" ReadOnly="True" SortExpression="InvoiceDueDate" />
                <asp:BoundField DataField="InvoiceAmt" HeaderText="Amount" ReadOnly="True" SortExpression="InvoiceAmt" />
                 <asp:BoundField DataField="PaidAmt" HeaderText="Amount Paid" ReadOnly="True" SortExpression="PaidAmt" />
                <asp:BoundField DataField="InvoiceStatus" HeaderText="Status" ReadOnly="True" SortExpression="InvoiceStatus" />
                <asp:TemplateField>
                     <ItemTemplate> 
                        <asp:Button ID="btnPay" CssClass="btn" runat="server" OnClick="PayInvoice_Click" Text="Pay" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                     <ItemTemplate> 
                        <asp:Button ID="btnView" CssClass="btn" runat="server"  OnClick="ViewInvoice_Click" Text="View Details" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Open in new window

aspx.cs (what i did, the btnPay has red lines on it)
    protected void PayInvoice_Click(object sender, EventArgs e)
    {
            GridViewRow gridviewRow = (GridViewRow)((Button)sender).NamingContainer;
            if (gridviewRow != null)
            {
                var invoiceId = int.Parse(gridviewRow.Cells[0].Text);
                if (invoiceId > 0)
                {
                    Response.Redirect("~/AdminE_PayInvoice.aspx?InvoiceId=" + invoiceId);
                }
                var status = (gridviewRow.Cells[5].Text);
                if (status == "Full Payment")
                {
                   btnPay.Visible = false;
                }
            }      
        }

Open in new window

JayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
I'd check just what the value in 'status' is.  (Note "Full Payment" is not equal to "full payment" for example)
0
Ryan ChongCommented:
what i did, the btnPay has red lines on it
in general, since btnPay is a control within your gridview's template field, you can't directly refer to it...

another issue is: do you want to make the button invisible only after it was being clicked OR want to make it invisible when the gridview was loaded?
0
JayAuthor Commented:
@ryan : invisible after clicking the create button !!
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Ryan ChongCommented:
to be frank, no idea why you want to hide the button while at the end you are doing a page redirection...

anyway, try something like this:
protected void PayInvoice_Click(object sender, EventArgs e)
        {
            GridViewRow gridviewRow = (GridViewRow)((Button)sender).NamingContainer;
            if (gridviewRow != null)
            {
                var invoiceId = int.Parse(gridviewRow.Cells[0].Text);
                
                var status = (gridviewRow.Cells[5].Text);
                if (status == "Full Payment")
                {
                    Button btnPay = (Button)gridviewRow.FindControl("btnPay");
                    if (btnPay != null)
                    {
                        btnPay.Visible = false;
                    }
                }

                //Only do redirection here
                //Hide the codes first so you can see effect above
                /*
                if (invoiceId > 0)
                {
                    Response.Redirect("~/AdminE_PayInvoice.aspx?InvoiceId=" + invoiceId);
                }*/
            }  
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JayAuthor Commented:
It’s bc if the customer hasn’t paid anything yet, the admin then wouldn’t be able to see what the use has paid bc there’s no payment !! And yr codes work thank u :)
0
Ryan ChongCommented:
glad that codes were working fine. so you may proceed to close this question cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

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.