2016-12-01 38 views
0

我真的不知道該怎麼說這個問題,所以如果有人對我如何改進措辭有任何建議,我會很樂意改變它。如何獲取GridView單元格中的值以傳遞前端的函數?

我需要知道如何從單擊按鈕的GridViewRow中獲取單元格的值。我有以下的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> 

你會發現,我在我的TemplateField 2點了LinkBut​​ton。第一個按鈕GvBtnApprove有一個綁定到其Visible屬性的功能。背後的IsApproveVisible()函數的代碼是在這裏:

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 

該函數採用名爲mip_status參數。此參數的值保存在GridView中每行的單元格12中。我怎樣才能得到這個值傳遞給IsApproveVisible()函數?如果您想知道,我打算爲GvBtnDeny做同樣的事情。任何幫助是極大的讚賞。

回答

1

您可以使用

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

如果你真的想使用索引來獲取值,你可以使用這個

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

非常感謝!我知道必須有某種我想要的語法,但我無法在任何地方找到它。這工作像一個魅力。 – ic3man7019

相關問題