ic3man7019
ic3man7019

Reputation: 711

How can I get the value in a GridView cell to pass in a function on the front end?

I didn't really know how to word this question, so if anyone has any suggestions as to how I can improve the wording, I would be glad to change it.

I need to know how to get the value of a cell in a GridViewRow from which a button is clicked. I have the following GridView:

<asp:GridView ID="Gv_MipData" AllowSorting="true" runat="server" CssClass="GridViewStyle"
    PageSize="30" Width="100%" AllowPaging="true">
    <RowStyle CssClass="RowStyle" />
    <EmptyDataRowStyle CssClass="EmptyRowStyle" />
    <PagerSettings Position="TopAndBottom" />
    <PagerStyle CssClass="PagerStyle" />
    <SelectedRowStyle CssClass="SelectedRowStyle" />
    <HeaderStyle CssClass="HeaderStyle" />
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="GvBtnApprove" runat="server" CausesValidation="False" Style='display: block; width: 100px;'
                    CommandName="Approve" CssClass="buttonlggrid" Text="Approve" OnClick="ApproveButtonClick"
                    OnClientClick="return confirm('Are you sure you want to approve this suggestion?');"
                    Visible='<%# IsApproveVisible() %>'>
                </asp:LinkButton>
                <asp:LinkButton ID="GvBtnDeny" runat="server" CausesValidation="False" Style='display: block; width: 100px;'
                    CommandName="Deny" CommandArgument="<%#Container.DataItemIndex %>"
                    CssClass="buttonlggrid" Text="Deny" OnClick="DenyButtonClick">
                </asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

You'll notice that I have two LinkButtons in my TemplateField. The first button, GvBtnApprove has a function bound to its Visible property. The code behind for the IsApproveVisible() function is here:

Protected Function IsApproveVisible(mip_status As String) As Boolean
    If mip_status = "Pending" Then
        Return True
    ElseIf mip_status = "Approved" Then
        Return False
    Else
        Return True
    End If
End Function

The function takes a parameter called mip_status. The value for this parameter is saved in cell 12 of each row in the GridView. How can I get this value to pass it in to the IsApproveVisible() function? I am planning on doing the same thing for GvBtnDeny if you're wondering. Any help is greatly appreciated.

Upvotes: 0

Views: 472

Answers (1)

VDWWD
VDWWD

Reputation: 35514

You can use

Visible='<%# IsApproveVisible(Eval("columnName").ToString) %>'

And if you really want to use an index to get the value you can use this

Visible='<%# IsApproveVisible(Eval("[12]").ToString) %>'

Upvotes: 1

Related Questions